我的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中运行良好。
发布于 2018-01-03 20:56:46
发生了什么事
编译上下文中有两个react.d.ts。
修复
再次删除node_modules和任何package-lock (或纱线锁)和npm install。
如果它不能工作,找到无效模块(所有模块都应该将react.d.ts作为peerDependency而不是硬dependency)并报告其项目。
https://stackoverflow.com/questions/48084260
复制相似问题