2015-06-27 78 views
0

我希望能夠到另一個打字稿環境聲明和實現在不同的文件

例爲對象的環境聲明在一個文件中,而是提供實現:

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; 
})(); 

錯誤:

Subsequent variable declarations must have the same type. Variable 'Test' must be of type 'TestConstructor', but here has type '(value: any) => void'.

我知道這似乎是使用打字稿的一種奇怪的方式,但原因是我希望建立與打字稿不支持的功能(關閉對象/值屬性),所以我不能使用這個類。

此外,我想出貨Test.d.ts和Test.js,但不是Test.ts

回答

2

您的代碼並不表明Test.ts需要引用Test.d.ts,所以只是通過自身

編譯 Test.ts

tsc Test.ts

,而不是

tsc Test.ts Test.d.ts

+0

燦這是從視覺工作室完成的? – series0ne

+0

我有一段時間沒有使用過Visual Studio,所以可能會有比這更好的方法。您可以將這些文件放在單獨的項目中。您也可以將Test.d.ts的Build Action屬性更改爲None,但如果該文件包含錯誤,編譯器將無法捕獲它們。 – curpa