简体   繁体   English

因果类型脚本接口XXX不能同时扩展类型'YYY

[英]Karma-typescript Interface XXX cannot simultaneously extend types ' YYY

My tsconfig.json is 我的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"]
  }
}

And I have added the karma-typescript to my config 而且我已经将karma-typescript添加到我的配置中

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

Using webpack, the dev-server and compiling works fine. 使用webpack,开发服务器和编译工作正常。

And here is a dummy test 这是一个虚拟测试

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

When running the test, I get 运行测试时,我得到

node_modules/@types/react/index.d.ts(2736,19): error TS2320: Interface 'ElementClass' cannot simultaneously extend types 'Component' and 'Component'. node_modules/@types/react/index.d.ts(2736,19):错误TS2320:接口'ElementClass'无法同时扩展类型'Component'和'Component'。 Named property 'props' of types 'Component' and 'Component' are not identical. 类型为“组件”和“组件”的命名属性“ props”不同。

And similar to those. 和那些相似。 If I remove settings.preprocessors['test-bundler.js'].unshift('karma-typescript'); 如果我删除settings.preprocessors['test-bundler.js'].unshift('karma-typescript'); then the test runs fine (but then I cannot pre-compile typescript when I start to import my source files. 然后测试运行正常(但是当我开始导入源文件时,我无法预编译打字稿。

What is going on? 到底是怎么回事? My normal build and dev-server run fine with the tsconfig.json I have 我的常规构建和开发服务器在tsconfig.json运行良好

What is going on 到底是怎么回事

You have two react.d.ts in the compilation context. 您在编译上下文中有两个react.d.ts

Fix 固定

Delete node_modules and any package-lock (or yarn lock) and npm install again. 删除node_modules和所有package-lock (或yarn锁定),然后再次npm install

If it doesn't work, find the invalid module (all modules should have react.d.ts as a peerDependency and not a hard dependency ) and report it on their project. 如果它不起作用,请找到无效的模块(所有模块都应具有react.d.ts作为peerDependency而非硬dependency ),并在其项目中报告该模块。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM