[英]How to Setup VS Code For Creating TypeScript Definition Files
我有這個當前的文件夾結構:
project
└───typings
│ | index.d.ts
| FileToMakeTdFor.js
| FileToMakeTdFor-Tests.ts
我有一個JS文件,正在嘗試為其創建Typescript定義(d.ts)。
js文件如下所示:
"use strict";
var FileToMakeTdFor = (function () {
function FileToMakeTdFor(config) {
...
}
FileToMakeTdFor.prototype.example = function () {
...
};
return CRMWebAPI;
}());
exports.FileToMakeTdFor = FileToMakeTdFor;
index.d.ts文件如下所示:
export interface FileToMakeTdFor {
new (config:any): FileToMakeTdFor;
example(): void;
}
在我的測試文件中,我試圖寫成這樣:
let obj = new FileToMakeTdFor();
obj.example();
但是我在構造函數上遇到錯誤, Cannot find name FileToMakeTdFor
如何使測試ts文件找到index.d.ts文件? 有沒有更好的方法來設置此結構?
特別感謝Dave Hillier的鏈接 。 它使我進入了TypeScript 手冊中的聲明文件 。 顯然我只是錯過了一些出口電話:
/*~ If this module is a UMD module that exposes a global variable 'CRMWebAPI' when
*~ loaded outside a module loader environment, declare that global here.
*~ Otherwise, delete this declaration.
*/
export as namespace FileToMakeTdFor;
/*~ This declaration specifies that the class constructor function
*~ is the exported object from the file
*/
export = FileToMakeTdFor;
export interface FileToMakeTdFor {
new (config:any): FileToMakeTdFor;
example(): void;
}
一旦我將export as namespace FileToMakeTdFor;
添加export as namespace FileToMakeTdFor;
並export = FileToMakeTdFor;
線,一切開始工作...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.