组件不能用作 JSX 组件。属性“$props”类型 X 中缺失,但类型“ElementClass”中必需

发布于 2025-01-11 03:12:26 字数 1252 浏览 0 评论 0原文

我几乎从 VSCode 中的每个组件(自定义组件和库组件)中收到此打字稿错误。这是一个针对 React Native 的博览会构建。此命令产生相同的结果: yarn tsc --project tsconfig.json

这是 VSCode 中的示例 输入图片此处的描述

以及完整错误消息的示例:

'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

here's an example in VSCode
enter image description here

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

扛起拖把扫天下 2025-01-18 03:12:26

我有同样的问题
我刚刚将其添加到 package.json,然后

"resolutions": {
   "@types/react": "17.0.2",
   "@types/react-dom": "17.0.2"
},

按照此处所述运行yarn

I had the same problem
I just added this to package.json then run yarn

"resolutions": {
   "@types/react": "17.0.2",
   "@types/react-dom": "17.0.2"
},

as mentioned here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文