组件不能用作 JSX 组件。属性“$props”类型 X 中缺失,但类型“ElementClass”中必需
我几乎从 VSCode 中的每个组件(自定义组件和库组件)中收到此打字稿错误。这是一个针对 React Native 的博览会构建。此命令产生相同的结果: yarn tsc --project tsconfig.json
以及完整错误消息的示例:
'KeyboardAvoidingView' cannot be used as a JSX component.
Its instance type 'KeyboardAvoidingView' is not a valid JSX element.
Property '$props' is missing in type 'TimerMixin & KeyboardAvoidingViewComponent' but required in type 'ElementClass'.ts(2786)
这是我的 .tsconfig:
{
"extends": "../../node_modules/expo/tsconfig.base",
"compilerOptions": {
"jsx": "react-native",
"strict": true
}
}
这是它扩展的 expo:
{
"$schema": "https://json.schemastore.org/tsconfig",
"display": "Expo",
"compilerOptions": {
"allowJs": true,
"esModuleInterop": true,
"jsx": "react-native",
"lib": ["DOM", "ESNext"],
"moduleResolution": "node",
"noEmit": true,
"resolveJsonModule": true,
"skipLibCheck": true,
"target": "ESNext"
},
"exclude": ["node_modules", "babel.config.js", "metro.config.js", "jest.config.js"]
}
I'm getting this typescript error from basically every component in VSCode, both custom and library components. This is an expo build for react native. This command yields the same results:yarn tsc --project tsconfig.json
and an example of the full error message:
'KeyboardAvoidingView' cannot be used as a JSX component.
Its instance type 'KeyboardAvoidingView' is not a valid JSX element.
Property '$props' is missing in type 'TimerMixin & KeyboardAvoidingViewComponent' but required in type 'ElementClass'.ts(2786)
This is my .tsconfig:
{
"extends": "../../node_modules/expo/tsconfig.base",
"compilerOptions": {
"jsx": "react-native",
"strict": true
}
}
and this is expo's that it extends:
{
"$schema": "https://json.schemastore.org/tsconfig",
"display": "Expo",
"compilerOptions": {
"allowJs": true,
"esModuleInterop": true,
"jsx": "react-native",
"lib": ["DOM", "ESNext"],
"moduleResolution": "node",
"noEmit": true,
"resolveJsonModule": true,
"skipLibCheck": true,
"target": "ESNext"
},
"exclude": ["node_modules", "babel.config.js", "metro.config.js", "jest.config.js"]
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我有同样的问题
我刚刚将其添加到 package.json,然后
按照此处所述运行yarn
I had the same problem
I just added this to package.json then run yarn
as mentioned here