【发布时间】:2017-02-20 08:11:29
【问题描述】:
从 1.8 转换为 typescript 2.0 后,我遇到了很多错误。 错误和打字稿代码是。
找不到“JSON”
set = JSON.parse(settin);
属性 'indexOf' ,类型 'string' 上不存在 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
{
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"outDir": "out",
"noLib": true,
"sourceMap": true
},
"exclude": [
"node_modules"
]
}
【问题讨论】:
-
听起来好像没有提到
lib.d.ts。你是怎么升级的?是运行tsc之后的错误信息吗? -
我刚刚将 package.json 中的 TS 版本替换为 2.0.3 并删除了 node_modules 文件夹并再次运行 npm install。
tsc已在 tsconfig.json 中设置,我已在帖子中发布了该 json。
标签: javascript typescript ecmascript-6 typescript2.0