我希望能够在一个文件中为对象提供环境声明,但在另一个文件中提供实现
Example:
Test.d.ts
interface TestConstructor {
new(value?: any): void;
...
}
interface Test {
...
}
declare var Test: TestConstructor;
Test.ts
var Test = (function () {
function Test(value) {
}
return Test;
})();
Error:
后续变量声明必须具有相同的类型 . 变量'Test'必须是'TestConstructor'类型,但这里有类型'(value:any)=> void' .
我知道这似乎是使用TypeScript的一种奇怪方式,但原因是我想构建一个具有TypeScript不支持的功能的对象(闭包/值属性),所以我不能使用类来实现这一点 .
另外我想发送Test.d.ts和Test.js,但不是Test.ts
1 回答
您的代码并不表示
Test.ts
需要引用Test.d.ts
,所以只需编译Test.ts
本身tsc Test.ts
代替
tsc Test.ts Test.d.ts