【问题标题】:Typescript reference comment for working用于工作的打字稿参考注释
【发布时间】:2015-01-22 21:12:30
【问题描述】:

我正在使用 Visual Studio 2013 Ultimate Update 4 和 Typescript。

我有一个像 MyClass.ts 这样的类:

/// <reference path="interfaces/IMyClass"/>
export = MyModule;

module MyModule {
class MyClass {
    constructor(myObject: IMyClass){....}
    ...
}
}

还有另一个 MyInterface.ts:

export = MyModule;

module MyModule {

interface IMyClass {
    ...
}
}

VS2013 不承认 MyClass 文件中的 IMyClass 引用(也没有智能感知),但引用的行为就像 VS 可以看到它一样(没有红色下划线表示它找不到文件)。

如果我将接口文件名更改为 MyInterface.d.ts,它会做同样的事情。

如果我将 MyInterface.d.ts 中的界面更改为:

//export = MyModule ;

declare module MyModule {

interface IMyClass {
    ...
}
}

它也失败了。

如果我将 MyInterface.d.ts 中的界面更改为:

//export = MyInterfaces ;

declare module MyInterfaces {

interface IMyClass {
    ...
}
}

它有效。

我错过了什么吗?所以我们只能对.d.ts文件使用引用cmets,并且导出的模块名称可以相同??

我发现 typescript 中模块周围的很多东西令人困惑。

提前致谢。

【问题讨论】:

    标签: visual-studio-2013 typescript


    【解决方案1】:

    VS2013 不承认 MyClass 文件中的 IMyClass 引用(也没有智能感知),

    两个使用外部模块的TypeScript文件之间的模块MyModule是不同的。因此,您不会在第二个文件MyModule 中获得interface IMyClass

    提示:您可能需要查看 TypeScript 中的 internalexternal 模块(提示:如果您使用外部模块,请不要使用内部模块)。 https://www.youtube.com/watch?v=KDrWLMUY0R0&hd=1

    【讨论】:

    • 谢谢,我一直在使用 Typescript 语言规范作为参考。我在 2.3 中看到“接口、枚举和内部模块是“开放式的”,这意味着接口、枚举和内部模块声明相对于公共根具有相同的限定名称会自动合并。”,但我没有看到任何说外部模块不能发挥相同作用的东西。外部模块不是开放式的吗?
    猜你喜欢
    • 2022-11-24
    • 1970-01-01
    • 2021-06-09
    • 2021-09-20
    • 1970-01-01
    • 1970-01-01
    • 2016-06-06
    • 2012-12-09
    • 1970-01-01
    相关资源
    最近更新 更多