【发布时间】:2017-05-21 08:46:36
【问题描述】:
我有这个当前的文件夹结构:
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 文件?有没有更好的方法来设置这个结构?
【问题讨论】:
-
这有帮助吗:stackoverflow.com/a/39237584/1575281 这是 2.0.0 之前的版本
-
如果代码和测试代码一起编译,则无需创建定义文件。它应该开箱即用。您的问题可能出在其他地方。
-
另外,你是如何导入
FileToMakeTdFor模块的?
标签: javascript typescript visual-studio-code