Typescript 在3.1 don'之后键入脚本;t接受回调函数参数类型

Typescript 在3.1 don'之后键入脚本;t接受回调函数参数类型,typescript,jquery-terminal,Typescript,Jquery Terminal,我和你有这个问题。我有一个相当大的d.ts文件,但它不能正常工作。我试图更新依赖项,但一切都坏了。从一段时间以来,我无法更新TypeScript,因为我收到了这种类型的错误(3.1之后的版本) 甚至回调函数也定义了类型 我已经检查了TypeScript Playerd,这很好: type arg = ((x: number) => number) | number; function hey(list: arg[]) { list.forEach(x => { if (t

我和你有这个问题。我有一个相当大的d.ts文件,但它不能正常工作。我试图更新依赖项,但一切都坏了。从一段时间以来,我无法更新TypeScript,因为我收到了这种类型的错误(3.1之后的版本)

甚至回调函数也定义了类型

我已经检查了TypeScript Playerd,这很好:

type arg = ((x: number) => number) | number;
function hey(list: arg[]) {
  list.forEach(x => {
    if (typeof x === 'function') {
      x(10);
    }
  });
}

hey([10, function(x) { x.toFixed(10); return x }]);
当我使用hey时,我有一个没有类型的函数,类型取自我的回调定义。有人知道为什么会发生这种情况以及如何解决吗? 问题是,当我不更新typescript时,我从babel_traverse中得到了错误,就像typescript不打字检查代码从typescript中得到了数千个无效语法错误请参见:

如果你不知道答案,也许你知道如何调试我的typescript d.ts文件,这样我就能自己找到问题

编辑:

这是类型声明的一部分:

类型typeorary=T | T[];
声明命名空间JQueryTerminal{
输入解释器函数=(this:JQueryTerminal,command:string,term:JQueryTerminal)=>any;
类型terminalObjectFunction=(…参数:(字符串|数字| RegExp)[])=>(void |类型或promise);
类型解释器=字符串|解释器函数|对象解释器;
类型ObjectInterpreter={
[键:字符串]:ObjectInterpreter | terminalObjectFunction;
}   
}
接口JQuery{
终端(解释器?:类型数组,选项?:终端选项):JQueryTerminal;
}
问题是,这在以前版本的TypeScript中工作得很好

这是我的
tsconfig.json

{
    "compilerOptions": {
        "target": "es6",
        "module": "commonjs",
        "strict": true,
        "lib": ["es2015", "ES2018.Promise", "dom"]
    },
    "exclude": ["npm"]
}
我在test.ts中有一个用于检查CI中的类型:

/// <reference path="./js/jquery.terminal.d.ts" />

import "jquery";
import "jquery.terminal";


function test_type<T>(x: T) {};

// this works
$('.term').terminal(function(command, term) {
    term.echo(command);
});
// this also works
$('.term').terminal(function(command) {
    this.echo(command);
});
// this doesn't work, function in array
$('.term').terminal([function(command, term) {
    term.echo(command);
    return Promise.resolve(document.createElement('div'));
}]);
//
导入“jquery”;
导入“jquery.terminal”;
函数测试_型(x:T){};
//这很有效
$('.term').terminal(函数(命令,术语){
术语.echo(命令);
});
//这同样有效
$('.term').terminal(函数(命令){
这个.echo(命令);
});
//这不起作用,在数组中运行
$('.term').terminal([函数(命令,术语)]{
术语.echo(命令);
返回Promise.resolve(document.createElement('div'));
}]);

用显式函数重载替换
TypeOrArray
似乎可以解决此问题:

interface JQuery<TElement = HTMLElement> {
   terminal(interpreter?: JQueryTerminal.Interpreter): any;
   terminal(interpreter?: JQueryTerminal.Interpreter[]): any;
}
接口JQuery{
终端(解释器?:JQueryTerminal.translator):任意;
终端(解释器?:JQueryTerminal.translator[]):任意;
}

那么如何键入
命令?你能分享你的
d.ts
文件的相关部分吗?@thedude添加了相关的类型。我不知道为什么,但它在我的项目中不起作用,我已经改为代码,还尝试使用本地文件作为jQuery终端,我的typescript测试运行失败,但出现了相同的错误。
interface JQuery<TElement = HTMLElement> {
   terminal(interpreter?: JQueryTerminal.Interpreter): any;
   terminal(interpreter?: JQueryTerminal.Interpreter[]): any;
}