Karma-typescript 接口 XXX 不能同时扩展类型 'YYY

Karma-typescript Interface XXX cannot simultaneously extend types ' YYY

我的 tsconfig.json

{
  "compilerOptions": {
    "outDir": "./dist/",
    "sourceMap": true,
    "module": "es6",
    "target": "es5",
    "jsx": "react",
    "allowJs": true,
    "preserveConstEnums": true,
    "removeComments": true,
    "noImplicitAny": false,
    "moduleResolution": "node",
    "noUnusedParameters": true
  },
  "include": [
    "./src/**/*"
  ],
  "exclude": [
    "node_modules",
    "@typings",
    "typings/main",
    "typings/main.d.ts",
    "typings/index.d.ts"
  ],
  "paths": {
    "react": ["node_modules/@types/react"]
  }
}

并且我已将 karma-typescript 添加到我的配置中

settings.frameworks.push('karma-typescript');
settings.preprocessors['test-bundler.js'].unshift('karma-typescript');
settings.karmaTypescriptConfig = {
    tsconfig: './tsconfig.json',
};

使用 webpack,开发服务器和编译工作正常。

这是一个虚拟测试

describe('Root', () => {
    it('should pass', () => {
        console.log('done');
    });
});

当运行测试时,我得到

node_modules/@types/react/index.d.ts(2736,19): error TS2320: Interface 'ElementClass' cannot simultaneously extend types 'Component' and 'Component'. Named property 'props' of types 'Component' and 'Component' are not identical.

和那些类似。如果我删除 settings.preprocessors['test-bundler.js'].unshift('karma-typescript'); 那么测试 运行 很好(但是当我开始导入我的源文件时我无法预编译打字稿。

这是怎么回事?我的正常构建和开发服务器 运行 与 tsconfig.json 我有

What is going on

您在编译上下文中有两个 react.d.ts

修复

再次删除node_modules和任何package-lock(或纱线锁)和npm install

如果它不起作用,找到无效的模块(所有模块都应该有 react.d.ts 作为 peerDependency 而不是硬 dependency)并在他们的项目中报告它。