-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Normalize usage of types ReactNode
and ReactNodeLike
#16054
Comments
Thanks for opening this up. The mismatch here should definitely be fixed. Which way to fix it I'm unsure on. We state support for react 16, 17, and 18. It sounds like using ReactNode might cause typescript errors for 17 and 18 users in certain scenarios. Avoiding using I'm not opposed to consolidating on using ReactNode for now, and we'll keep an eye on feedback if it's problematic. |
Could you point me to some info regarding the potential errors with
Are you open to contributions on this? We could consolidate these incrementally as we work on other issues. |
@cuppajoey Yes here's one example from slack
Yes absolutely, we can do them incrementally as we work on other stuff. @Gururajj77 could you add a list here of all components that need to be modified? |
Package
@carbon/react
Browser
No response
Package version
v1.53.0
React version
v16.140
Description
The types defined for
TextArea.labelText
andTextInput.labelText
do not match. The former is typed asprop-types.ReactNodeLike
while the latter is typed asReact.ReactNode
. In older versions ofReact
,ReactNode
included support for{}
, but has since been removed. Consumers who haven't yet upgraded to React 18 can experience type errors (as demonstrated in the included StackBlitz demo) between two props which should accept the same data types.While this issue can be worked around, I wanted to take this opportunity to highlight an inconsistent practice when writing types for props that accept a
ReactNode
. Currently many component props acceptReactNode
while others acceptReactNodeLike
, e.g.,TextArea
andTextInput
. In some cases both types are being used within the same component (TextInput.labelText
vsTextInput.slug
).From my understanding,
ReactNodeLike
is meant to matchReactNode
without being dependent on React itself (See DefinitelyTyped/DefinitelyTyped#29194). However, since@carbon/react
has a direct dependency onreact
, we should useReactNode
exclusively instead of relying on two packages for what is essentially the same type definition.If the maintainers agree, I'm happy to contribute a fix for this myself 👍.
All the components that have the intertwining between the typescript
interface
and type annotations from theprop-types
library:Tasks
ReactNode
for types in NumberInput #16410ReactNode
for types inRadioButton
#16411ReactNode
for types inRadioButtonGroup
#16412ReactNode
for types inSelect
#16414ReactNode
for types inSlider
#16416ReactNode
for types inDismissableTag
#16417ReactNode
for typescript types inOperationalTag
#16419ReactNode
for typescript types inSelectableTag
#16420ReactNode
for typescript types inTag
#16421ReactNode
for typescript types inText
#16422ReactNode
for typescript types inTextArea
#16423ReactNode
for typescript types inPasswordInput
#16424ReactNode
for typescript types inTextInput
#16425ReactNode
for typescript types inTile
#16426ReactNode
for typescript types inTileGroup
#16427You can take up each component as a separate issue and work on it.
Reproduction/example
https://stackblitz.com/edit/github-bcs3rp?file=src%2FInput.tsx
Steps to reproduce
src/Input.tsx
.labelText
in theTextArea
on line 12.Suggested Severity
None
Application/PAL
No response
Code of Conduct
The text was updated successfully, but these errors were encountered: