【发布时间】:2023-03-13 08:38:01
【问题描述】:
代码编译并运行,但类型检查出现错误,导致大量文件和变量爆炸。这是一个例子。
Test1.ts
import Test2 = require('./Test2');
class Test1 {
test2: Test2;
constructor() {
this.test2 = new Test2();
}
}
console.log(new Test1());
Test2.ts
export = class Test2 {
prop: number;
constructor() {
this.prop = 5;
}
}
运行tsc --module commonjs Test1.ts 给我这个错误:
Test1.ts(4,12): error TS2304: Cannot find name 'Test2'.
并运行代码输出:
Test1 { test2: Test2 { prop: 5 } }
我在这里做错了什么?
【问题讨论】:
标签: typescript