Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

React18&taro-ui关于children属性缺失 #1540

Closed
fguizc opened this issue Sep 26, 2022 · 1 comment · Fixed by #1543
Closed

React18&taro-ui关于children属性缺失 #1540

fguizc opened this issue Sep 26, 2022 · 1 comment · Fixed by #1543

Comments

@fguizc
Copy link

fguizc commented Sep 26, 2022

相关平台

H5

复现仓库

https://github.com/fguizc/taro-mini-repo
**浏览器版本: 105.0.5195.102 (正式版本) (arm64) **
使用框架: React

复现步骤

任意 React18 taro-ui 项目中使用如:

<AtButton>下一步</AtButton>

会提示 类型“IntrinsicAttributes & IntrinsicClassAttributes<Component<AtButtonProps, any, any>> & Readonly”上不存在属性“children”。

期望结果

ts 能够正常推到,并且不提示关于 children 的错误

实际结果

不能将类型“{ children: (string | Element)[]; type: "primary"; onClick: () => void; }”分配给类型“IntrinsicAttributes & IntrinsicClassAttributes<Component<AtButtonProps, any, any>> & Readonly”。
类型“IntrinsicAttributes & IntrinsicClassAttributes<Component<AtButtonProps, any, any>> & Readonly”上不存在属性“children”。

由于 React18 移除了 FC 定义中默认的 children: React.ReactNode,因此此类封装的组件都会提示缺少 children 属性

环境信息

Taro v3.5.6


  Taro CLI 3.5.6 environment info:
    System:
      OS: macOS 12.0.1
      Shell: 5.8 - /bin/zsh
    Binaries:
      Node: 16.15.1 - /usr/local/bin/node
      Yarn: 1.22.17 - /usr/local/bin/yarn
      npm: 8.11.0 - /usr/local/bin/npm
    npmPackages:
      @tarojs/cli: 3.5.6 => 3.5.6
      @tarojs/components: 3.5.6 => 3.5.6
      @tarojs/helper: 3.5.6 => 3.5.6
      @tarojs/plugin-framework-react: 3.5.6 => 3.5.6
      @tarojs/plugin-platform-alipay: 3.5.6 => 3.5.6
      @tarojs/plugin-platform-jd: 3.5.6 => 3.5.6
      @tarojs/plugin-platform-qq: 3.5.6 => 3.5.6
      @tarojs/plugin-platform-swan: 3.5.6 => 3.5.6
      @tarojs/plugin-platform-tt: 3.5.6 => 3.5.6
      @tarojs/plugin-platform-weapp: 3.5.6 => 3.5.6
      @tarojs/react: 3.5.6 => 3.5.6
      @tarojs/router: 3.5.6 => 3.5.6
      @tarojs/runtime: 3.5.6 => 3.5.6
      @tarojs/shared: 3.5.6 => 3.5.6
      @tarojs/taro: 3.5.6 => 3.5.6
      @tarojs/taro-h5: 3.5.6 => 3.5.6
      @tarojs/webpack5-runner: 3.5.6 => 3.5.6
      babel-preset-taro: 3.5.6 => 3.5.6
      eslint-config-taro: 3.5.6 => 3.5.6
      react: ^18.0.0 => 18.2.0
      taro-ui: ^3.1.0-beta.2 => 3.1.0-beta.3

补充信息

临时解决方案:

// index.d.ts
declare module "react" {
  interface Component {
    children: React.ReactElement;
  }
}
@ZakaryCode ZakaryCode transferred this issue from NervJS/taro Sep 26, 2022
@taro-ui-bot
Copy link

taro-ui-bot bot commented Sep 26, 2022

欢迎提交 Issue~

如果你提交的是 bug 报告,请务必遵循 Issue 模板的规范,尽量用简洁的语言描述你的问题,最好能提供一个稳定简单的复现。🙏🙏🙏

如果你的信息提供过于模糊或不足,或者已经其他 issue 已经存在相关内容,你的 issue 有可能会被关闭。

Good luck and happy coding~

@shinken008 shinken008 linked a pull request Sep 28, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant