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

TypeScript 组件类型错误 #233

Closed
HerbertHe opened this issue May 20, 2022 · 11 comments
Closed

TypeScript 组件类型错误 #233

HerbertHe opened this issue May 20, 2022 · 11 comments

Comments

@HerbertHe
Copy link
Contributor

image

@jaywcjlove
Copy link
Member

@HerbertHe 请使用 https://codesandbox.io 提供示例,我帮你看看。

@HerbertHe
Copy link
Contributor Author

@HerbertHe 请使用 https://codesandbox.io 提供示例,我帮你看看。

https://codesandbox.io/s/wonderful-booth-29cwqo?file=/src/App.tsx

这个问题我试了在 codesandbox 上无法复现,可能是与 vscode 或者 typescript 版本有关:

  • vscode 1.67.2 Windows11
  • typescript 4.6.4

@jaywcjlove
Copy link
Member

jaywcjlove commented May 21, 2022

我看你示例中使用 react 但是类型包用的是 17

"@types/react": "~18.0.9",
"@types/react-dom": "~18.0.3",

@HerbertHe 是不是这个也有可能是个问题?

@HerbertHe
Copy link
Contributor Author

我看你示例中使用 react 但是类型包用的是 17

"@types/react": "~18.0.9",
"@types/react-dom": "~18.0.3",

@HerbertHe 是不是这个也有可能是个问题?

应该不是的,我本地环境全都是 react 18,示例模板是 codesandbox 生成的

@jaywcjlove
Copy link
Member

看上去 @gamecss 好像修复了这个问题 @HerbertHe

@HerbertHe
Copy link
Contributor Author

@jaywcjlove 😂我没找到类型定义在哪之前。。

React有提供PropsWithChildren这个泛型类型API的,我感觉直接定义类型为ReactNode似乎不太合适(白天我看看修这个问题)

有计划升级到React18吗(,render方式的更改导致本地总是报错。

@jaywcjlove
Copy link
Member

@HerbertHe 欢迎提交 PR,可以及时处理,有空肯定升级

@HerbertHe
Copy link
Contributor Author

@jaywcjlove 主要是react18与之前的版本并不兼容,可能会有些同学的项目受影响,担心的主要是这个问题。支持react18就得做大版本升级了。

@jaywcjlove
Copy link
Member

@HerbertHe 使用了一种方法支持 React 18,现在支持 react 18 和 17 不需要发布大版本了。

@HerbertHe
Copy link
Contributor Author

@jaywcjlove 你这是把react打包进去了啊😂。。。有没有一种可能使用用户本地的react

@jaywcjlove
Copy link
Member

@HerbertHe 研究了一种方法使用 createPortal 来解决这个问题等待发版本。

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

No branches or pull requests

2 participants