尝试导入类失败。我正在使用Sublime Text 3。
导出类狗并导入类House。
filename Dog.ts
export class Dog {
static public sound = "Woof";
}
filename House.ts
import { Dog } from "./Dog"
class House {
TestDogSound () {
alert(Dog.sound);
}
}
所有的房子看到狗的对象,但它不起作用 收到此错误:
Uncaught Error: Module name "Dog" has not been loaded yet for context: _. Use require([])
希望它足够清楚,需要建议, 感谢。
编辑:添加tsconfig.json
{
"compilerOptions": {
"module": "commonJs",
// "noImplicitAny": true,
"removeComments": true,
"preserveConstEnums": true,
"sourceMap": true
},
"files": [
"Dog.ts",
"House.ts"
]
}