首页 > 解决方案 > Typescript 3.3 不再从 d.ts 文件中获取我的函数的类型

问题描述

在我的库 jQuery 终端中,我有用于类型的 d.ts 文件,我有用于测试类型的 test.ts,它只是使用了几乎所有 API,我正在执行 tsc 而不发出输出文件只是为了测试类型.

我已将 typescript 从 3.0 更新到 3.3,现在我的函数类型已损坏:代码如下所示,此示例更复杂,包含字符串、对象和函数的数组:

$('.term').terminal(["foo.php", obj_interpreter, function(command) {
    this.echo(command);
}]);

我有这样的类型:

declare namespace JQueryTerminal {
    type interpterFunction = (this: JQueryTerminal, command: string, term: JQueryTerminal) => any;
    type terminalObjectFunction = (this: JQueryTerminal, ...args: (string | number | RegExp)[]) => (void | PromiseLike<echoValue>);
    type Interpterer = string | interpterFunction | ObjectInterpreter;
    type ObjectInterpreter = {
        [key: string]: ObjectInterpreter | terminalObjectFunction;
    }
    ...
    type echoValue = string | string[] | (() => string | string[]);
    ...
}
interface JQuery<TElement = HTMLElement> {
    terminal(interpreter?: TypeOrArray<JQueryTerminal.Interpterer>, options?: TerminalOptions): JQueryTerminal;
    ...
}

这在 typescript 3.0 中运行良好,并且我已经在 Emacs 潮中完成了 this.echo 并且函数中的命令就像字符串一样,即使在用户代码中我没有指定类型。现在是否需要明确设置用户代码中的类型,这不是重大变化吗?为什么会这样?

供参考的是我损坏的 travis build

标签: typescriptjquery-terminal

解决方案


推荐阅读