【问题标题】:Typescript Compile Error in type definition files类型定义文件中的 Typescript 编译错误
【发布时间】:2016-05-27 23:08:57
【问题描述】:

我尝试将现有的 ES6 代码库迁移到 TypeScript 1.8。为了平滑路径,我尝试应用以下 typescript 编译器设置:

{
  "compilerOptions": {
    "target": "es6",
    "allowJs": true,
    "sourceMap": true,
    "jsx": "react",
    "outDir": "built"
  },
  "exclude": [
    "node_modules"
  ]
}

使用tsc 编译后,类型定义文件中有大量编译错误。

例子:

typings/main/definitions/sinon/sinon.d.ts(436,1): error TS2300: Duplicate identifier 'export='.
typings/main/definitions/sinon/sinon.d.ts(440,1): error TS2300: Duplicate identifier 'export='.

类型定义由typings维护。

希望有人能给我提示一下我的环境出了什么问题。

【问题讨论】:

    标签: typescript typescript1.8


    【解决方案1】:

    您的问题可能是 sinon 被包含了两次。原因是 Typings 创建了 main.d.tsbrowser.d.ts 并复制了一些文件。阅读更多关于 here 的信息。

    简而言之,您要做的是将 tsconfig 更改为类似于以下内容:

    {
      "compilerOptions": {
        "target": "es6",
        "allowJs": true,
        "sourceMap": true,
        "jsx": "react",
        "outDir": "built"
      },
      "exclude": [
        "node_modules",
        "typings/main",
        "typings/main.d.ts"
      ]
    }
    

    【讨论】:

      猜你喜欢
      • 2017-09-08
      • 1970-01-01
      • 1970-01-01
      • 2022-01-22
      • 1970-01-01
      • 1970-01-01
      • 2018-02-24
      • 2019-08-22
      • 1970-01-01
      相关资源
      最近更新 更多