typescript 错误 TS2602:JSX 元素隐式具有类型“any”,因为全局类型“JSX.Element”不存在
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/37674017/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
error TS2602: JSX element implicitly has type 'any' because the global type 'JSX.Element' does not exist
提问by Richard
Even though I've installed & referenced the Typings library 'react' like this
即使我已经像这样安装并引用了 Typings 库“反应”
/// <reference path="../../../typings/browser.d.ts" />
/// <reference path="../../../typings/browser.d.ts" />
I'm still getting the error below:
Is there another Typings library I should be installing as well?
我还应该安装另一个 Typings 库吗?
回答by darthtrevino
回答by Daniel Dyrnes
I resolved this issue by installing the react type definition.
我通过安装 react 类型定义解决了这个问题。
Try to run yarn add --dev @types/react
.
尝试运行yarn add --dev @types/react
。
回答by Daniel Dyrnes
Put this configuration in the tsconfig.json file so that the ts server does not recognize that type of errors
将此配置放在 tsconfig.json 文件中,以便 ts 服务器无法识别该类型的错误
{
"compilerOptions": {
"outDir": "build/dist",
"module": "commonjs",
"target": "es5",
"lib": ["es6", "dom"],
"sourceMap": true,
"allowJs": true,
"jsx": "react",
"moduleResolution": "node",
"rootDir": "src",
"noImplicitReturns": true,
"noImplicitThis": true,
"noImplicitAny": true,
"strictNullChecks": true
},
"exclude": [
"node_modules",
"build",
"scripts",
"acceptance-tests",
"webpack",
"jest",
"src/setupTests.ts"
],
"types": [
"typePatches"
]
}