【问题标题】:typescript intellisense issue for constructor overload构造函数重载的打字稿智能感知问题
【发布时间】:2017-08-03 01:48:03
【问题描述】:

我正在尝试使用打字稿编写插件。我声明了一个这样的接口:

interface Options {
  options1: string,
  options2: number,
  options3: boolean,
  ...
}

而且,我把它用作这个导出类可能采用的选项并重载它:

export class MyClass {
    constructor(public options: Options = {} as Options) {
        // options which can be overload
        let {
            /* default options: */
            option1 = 'option1',
            option2 = 2,
            option3 = true,
            ...
        }: Options = options as Options;
        // overload
        this.options.option1 = option1;
        this.options.option2 = option2;
        this.options.option3 = option3;
    }
}

最后我实例化了它。

const class1 = new MyClass({
    ...
})

我使用 vscode 作为我的编辑器。对我来说,intellisense 只给我这样的提示是没有意义的:

MyClass(选项?:选项)

我认为应该是这样的:

MyClass(options?: {options1: string, options2: number ... })

有人知道为什么会发生这种情况,以及如何使智能感知按预期工作吗?

【问题讨论】:

    标签: typescript visual-studio-code typescript-typings typescript2.0


    【解决方案1】:

    TypeScript 跟踪此问题存在问题。 But one issue with this approach is when the option is long, it does not give you the full detail anyway.

    它现在实际上工作得很好。你可以这样做:

    const class1 = new MyClass({
      // [Ctrl+space] here
    })
    

    它实际上会列出带有 IntelliSense 的选项属性option1option2 等。

    【讨论】:

    • 谢谢! [Ctrl+space] 得到我想要的。希望这个问题以后能解决。
    猜你喜欢
    • 2020-10-04
    • 1970-01-01
    • 1970-01-01
    • 2016-04-28
    • 2011-09-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-25
    相关资源
    最近更新 更多