从 1.8 转换为 Typescript 2.0 后,我遇到了很多错误。 错误和 typescript 代码是。
找不到“JSON”
set = JSON.parse(settin);
类型“string”上不存在属性“indexOf”、concat
var appSetting : string = this.en.APP_SETTINGS;
var appSummary : string = this.en.APP_SUMMARY;
while (appSetting.indexOf("/") > -1) {
appSetting = appSetting.replace("/", "\\");
}
找不到名称“对象”
public async GetSettings(): Promise<Object> {
无法在 Array() 中找到数组
let items: Array<string> = new Array<string>();
找不到日期
public lastUpload: Date = null;
也存在 require 和 Promise 等问题,但在添加 shim 和 types 后解决了
"devDependencies": {
"@types/es6-shim": "^0.31.32",
"typescript": "^2.0.3",
"vscode": "^1.0.0"
},
"dependencies": {
"@types/node": "^6.0.45",
"adm-zip": "^0.4.7",
"fs": "^0.0.2",
"github": "^2.6.0",
"ncp": "^2.0.0",
"node-watch": "0.4.0",
"open": "^0.0.5",
"rimraf": "^2.5.4",
"temp": "^0.8.3"
}
tsconfig.json
{
“编译器选项”:{
“模块”:“commonjs”,
“目标”:“es6”,
"outDir": "出",
“noLib”:正确,
“源 map ”:true
},
“排除”: [
“节点模块”
]
}
最佳答案
你有这一行:
"noLib": true
在 tsconfig.json
中,causes the compiler至
not include the default library file (lib.d.ts)
我实际上从未使用过它,但从你所描述的情况来看,如果你删除这一行,错误应该会消失。
关于javascript - 升级到 typescript 2 后找不到 (string)、Object、Date、Json 的需要索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39983114/