【问题标题】:Karma-typescript Interface XXX cannot simultaneously extend types ' YYYKarma-typescript Interface XXX 不能同时扩展类型' YYY
【发布时间】:2018-06-13 12:48:54
【问题描述】:

我的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):错误 TS2320:接口 “ElementClass”不能同时扩展类型“Component”和“Component”。类型的命名属性“道具” “组件”和“组件”不相同。

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

发生了什么事?我的正常构建和开发服务器在tsconfig.json 下运行良好

【问题讨论】:

    标签: javascript typescript karma-runner karma-webpack


    【解决方案1】:

    发生了什么

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

    修复

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

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

    【讨论】:

    • 是的,我知道 react-router 哈它是自己的 react.d.ts。我在运行dev-server 时遇到了同样的问题。解决方法是在我的tsconfig.json 中使用paths。我很惊讶在测试中没有得到尊重
    猜你喜欢
    • 2019-04-07
    • 1970-01-01
    • 2019-07-20
    • 2013-01-23
    • 1970-01-01
    • 2021-06-02
    • 2023-03-22
    • 2020-02-19
    • 2020-09-12
    相关资源
    最近更新 更多