-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Add ReactNode type docs #627
Conversation
docs/react-types/ReactNode.md
Outdated
} | ||
|
||
function Component({ children }: Props) { | ||
return <>{children}</>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return <>{children}</>; | |
return children; |
Latest types and TS will support that and that's the proper default. Everything else are workarounds for bugs. We have those documented I think somewhere and should link to it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Definitely should be the default. The problem I get (with latest @types/react and typescript) is that <Component>
implicitly gets ReactNode
as return type, which gives type error when I try to render <Component>
from another component:
import { ReactNode } from "react";
interface Props {
children?: ReactNode;
}
function Component({ children }: Props) {
return children;
}
function Example() {
return <Component>Hello</Component>; // 'Component' cannot be used as a JSX component. Its return type 'ReactNode' is not a valid JSX element.
}
Should this not produce a type error in latest @types/react and typescript?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will be fixed either today or tomorrow: microsoft/TypeScript#53031 (comment) + DefinitelyTyped/DefinitelyTyped#65135
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And now the TypeScript playground I linked just magically works. Amazing! Do you think we need to inform what version are required for this or should we should assume latest (as we actually state we do)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, thanks!
No description provided.