【问题标题】:Cannot find require index of (string) , Object, Date, Json after upgrading to typescript 2升级到 typescript 2 后找不到 (string)、Object、Date、Json 的要求索引
【发布时间】: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


【解决方案1】:

你有这行:

“noLib”:真

在你的tsconfig.json,其中causes the compiler

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

我实际上从未使用过它,但从您的描述看来,如果您删除此行,错误应该会消失。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-10-26
    • 2018-05-10
    • 1970-01-01
    • 1970-01-01
    • 2020-02-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多