-
Notifications
You must be signed in to change notification settings - Fork 358
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 PropsWithChildren type for components with children #7219
Conversation
Preview: https://patternfly-react-pr-7219.surge.sh A11y report: https://patternfly-react-pr-7219-a11y.surge.sh |
a29cbc3
to
a6fe62e
Compare
a6fe62e
to
1bca6e2
Compare
Can we get some eyes on this? I'll have to keep rebasing and fixing up this PR for most merges upstream. Note these changes are generated by means of a codemod, so if you'd like to make these changes yourself to verify there are no malicious changes you can run: npx types-react-codemod implicit-children .
yarn lint packages --fix |
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.
Hi @jonkoops, thank you for these updates!
I'm noticing that for all of the components declared with React.FunctionComponent<React.PropsWithChildren<unknown>>
, the react demo for that component doesn't render and displays SyntaxError: Unexpected token
. Do you have any idea why this might be happening?
Other demos look great and seem to render fine 👍
@redallen Perhaps you know how this works? I feel like the TypeScript code is stripped out by theme-patternfly-org somehow, but it trips up when a generic argument is provided? |
Unfortunately, redallen is not supporting this project anymore - but maybe we could have @wise-king-sullyman, @jschuler, @jeffpuzzo, or @dgutride take a peek |
I don't have extensive knowledge of org, but I can take a look into this today. A potentially silly question though: since the standard PF pattern is (at least as far as I'm aware) to declare an explicit |
@wise-king-sullyman you raise a good point, how about we just make sure that all components that currently depend on implicit children add |
@wise-king-sullyman I tried doing an upgrade to the React 18 types and there were quite some places where It does look however that this migration is applied everywhere where |
@jonkoops that's true, going the direction of only having If so it seems like we would need to proceed with this PR, at least until we can do a breaking change. |
IMO if a consumer uses a component that does not take children, but they still pass them, it's beneficial to "break" them since they might have the wrong assumption that something should be rendered even though it isn't. |
I agree with @jschuler. It's an opportunity to vet these components and if children are optional or required to specify the |
This should not result in having any children passed, at least not from a TypeScript perspective. I believe in the case for React it would simply provide I am a bit hesitant to commit changes that can cause errors in TypeScript, even when the consumer is wrong. For example, I contributed a breaking type change that resulted in (correct) type errors which was reverted (#6766 (comment)). Personally I agree with @jschuler and @jeffpuzzo but I'd like to have some confirmation before I manually check all of these instances, which is a significant workload. |
I would agree with @jschuler and @jeffpuzzo here. We should update any of our components that are not explicitly declaring children that expect the prop. We can open an issue for this and take on the work on our end and split it up with you. |
Awesome, then I think we have reached a conclusion on the approach. I'll go ahead and close this PR so we can instead focus on some smaller PRs that will update the types for individual components where necessary. |
Adds a type
PropsWithChildren
around all components that have children. In React 18 a component type (e.g.FunctionComponent
) no longer has an implicitchildren
prop. Adding thePropsWithChildren
type restores this behavior.This is needed to land #7142.