我有这堂课:
class AppViewModel {
setting: number = 1;
}
export = AppViewModel;
然后,我导入该类并使用它:
import AppViewModel = require("appViewModel");
class OrderEntry {
appViewModel = new AppViewModel();
doTest() {
alert(this.appViewModel.setting);
}
}
这很有效。但是,我想要的是单身人士。所以我将导出更改为:
export var instance = new AppViewModel();
稍微改变消费类:
import AppViewModel = require("appViewModel");
class OrderEntry {
appViewModel = AppViewModel;
doTest() {
alert(this.appViewModel.setting); //Error Here
}
}
但我得到一个说明
的complile time错误Property setting does not exist on type.
如何解决此问题?
答案 0 :(得分:0)
这对我有用:
var instance = new AppViewModel();
export = instance;
据我所知,Visual Studio显示类型为Any而不是AppViewModel。当我改为上面的内容时,它开始将其视为AppViewModel。