TypeScript 2.0 从排除的文件中抛出错误?

Geo*_*rds 4 node.js typescript typescript-typings typescript2.0

我有一个基于这个种子项目的nodeJS项目。它有两个tsconfig.json文件,如下所示:

{
    "compilerOptions": {
        "target": "es6",
        "module": "system",
        "moduleResolution": "node",
        "sourceMap": true,
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "removeComments": false,
        "noImplicitAny": false
    },
    "exclude": [
        "../node_modules"
    ]
}
Run Code Online (Sandbox Code Playgroud)

然而,尽管排除了node_modules,我还是收到了大量错误,其中一些错误如下所示。自从我开始使用新npm i @types/xyz方法以来,就发生了这种情况。

[0] node_modules/@types/core-js/index.d.ts(21,14):错误 TS2300:重复的标识符“PropertyKey”。

[0] node_modules/@types/core-js/index.d.ts(85,5): 错误 TS2687: 所有“name”声明必须具有相同的修饰符。

[0] node_modules/@types/core-js/index.d.ts(145,5): 错误 TS2403: 后续变量声明必须具有相同的类型。变量“[Symbol.unscopables]”必须为“{ copyWithin: boolean;”类型 条目:布尔值;填充:布尔值;查找:布尔值;查找索引:布尔值;键:...”,但这里输入的是“any”。

[0] node_modules/@types/core-js/index.d.ts(262,5): 错误 TS2687: 所有“flags”声明必须具有相同的修饰符。

[0] node_modules/@types/core-js/index.d.ts(276,5):错误 TS2687:“EPSILON”的所有声明必须具有相同的修饰符。

[0] node_modules/@types/core-js/index.d.ts(311,5):错误 TS2687:“MAX_SAFE_INTEGER”的所有声明必须具有相同的修饰符。

Ben*_*Ben 5

我刚刚使用 anguler2 项目升级到 ts2.0 后遇到了这个问题。\n我typings现在正在使用并且有很多依赖项。其中至少有一个包含 @types,它会重复一些导入。但它们是必需的,我不能只删除文件夹/依赖项(就像其他人建议的那样)。

\n\n

在这里我找到了一个对我有帮助的解决方案的指针:\n https://github.com/Microsoft/TypeScript/issues/11257

\n\n

来自 lucaspp 的示例:

\n\n
{\n    "compilerOptions": {\n        "target": "es6",\n        "module": "commonjs",\n        "moduleResolution": "node",\n        "sourceMap": true,\n        "emitDecoratorMetadata": true,\n        "experimentalDecorators": true,\n        "removeComments": false,\n        "noImplicitAny": false,\n        "types": []\n    },\n    "exclude": [\n        "../node_modules"\n    ]\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n

我只需添加"types": []到 tsconfig.json 文件,这使得它不包含 @types 中的任何类型(因为所有类型当前都是由类型管理的)。

\n\n

这是文档中编译器选项的描述:

\n\n
--types string[]\nList of names of type definitions to include. See @types, \xe2\x80\x93typeRoots and \xe2\x80\x93types for more details.\n
Run Code Online (Sandbox Code Playgroud)\n\n

微软似乎认为@types是新的黑色打字稿定义导入。请在此处阅读有关此内容的更多信息。

\n\n

最终我可能会迁移,但我会先让尘埃落定。

\n