javascript - 升级到 typescript 2 后找不到 (string)、Object、Date、Json 的需要索引

标签 javascript typescript ecmascript-6 typescript2.0

从 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/

相关文章:

html - 线不会因 Angular 而中断\n

angular - 如何将组件导入 Angular 中的服务类

javascript - 在另一个数组中更改数组内对象的对象属性

html - 如何隐藏一个div并将其替换为reactjs中的另一个div?

javascript - Jquery Deferred.resolve不传递参数

javascript - JS/jQuery : Best way to get typed characters after '#' in textarea

javascript - 在 Angular 2 中通过 URL 传递变量或设置变量

javascript - 在 ES6 中包装类函数并使用 super 的直接方法

javascript - 将数据从一个组件检索到另一组件

javascript - 正则表达式从完整 url 中删除文件名