升级到typescript 2后,找不到(string), Object, Date, Json的require索引

Cannot find require index of (string) , Object, Date, Json after upgrading to typescript 2

本文关键字:Object Date Json 索引 require string typescript 找不到      更新时间:2023-09-26

从1.8转换到typescript 2.0后,我得到了很多错误。错误和打字代码为。

无法找到"JSON"

set = JSON.parse(settin);

属性'indexOf', concat不存在类型'string'

var appSetting : string = this.en.APP_SETTINGS;
        var appSummary : string = this.en.APP_SUMMARY;
        while (appSetting.indexOf("/") > -1) {
            appSetting = appSetting.replace("/", "''");
        }

无法找到名称'Object'

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" ] }

你有这样一行:

"noLib":真正的

在你的tsconfig.json中,这会导致编译器

不包含默认库文件(lib.d.ts)

我实际上从未使用过,但是从你描述的情况来看,如果你删除这一行,错误应该会消失。