网站搜索

typescript1.8 - TypeScript 类型定义文件中的编译错误


我尝试将现有的 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 维护。

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

答案#1

您这里的问题很可能是 sinon 被包含了两次。原因是 Typings 创建了一个 main.d.ts 和一个 browser.d.ts,并且重复了一些文件。可以在这里阅读更多相关内容。

简而言之,你想要做的是将你的 tsconfig 修改为类似如下内容:

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