You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In a discussion in slack, we discovered that types for Button were incorrect for consumers, effectively making them React.FunctionComponent<any> instead of maintaining rich types.
After a quick investigation, it appeared like types were fine, going into the forwardRef that returned ButtonComponent but that they lost fidelity on that assignment.
At first glance, this appears as though forwardRef was swallowing a generic, leading to type broadening that allowed unexpected types.
That PR introduced the PolymorphicForwardRefComponent typing as a way to properly constrain the output types, which had previously been overly broadened.
We should probably do a larger bit of discovery around this
Add type tests for all components - specifically those related to a forwardRef or a memo call, where typescript might swallow those generics.
Update calls to forwardRef (and maybe memo) to use the polymorphic type where necessary
It's not immediately clear where/if this is necessary more than just on button, but we should also try to enforce type tests for new components. Maybe via a PR template update asking about them - as a first step?
The text was updated successfully, but these errors were encountered:
Hi! This issue has been marked as stale because it has been open with no activity for 180 days. You can comment on the issue or remove the stale label to keep it open. If you do nothing, this issue will be closed in 7 days.
Related to: #2445
In a discussion in slack, we discovered that types for
Button
were incorrect for consumers, effectively making themReact.FunctionComponent<any>
instead of maintaining rich types.After a quick investigation, it appeared like types were fine, going into the
forwardRef
that returnedButtonComponent
but that they lost fidelity on that assignment.At first glance, this appears as though
forwardRef
was swallowing a generic, leading to type broadening that allowed unexpected types.That PR introduced the
PolymorphicForwardRefComponent
typing as a way to properly constrain the output types, which had previously been overly broadened.We should probably do a larger bit of discovery around this
forwardRef
or amemo
call, where typescript might swallow those generics.forwardRef
(and maybe memo) to use the polymorphic type where necessaryIt's not immediately clear where/if this is necessary more than just on button, but we should also try to enforce type tests for new components. Maybe via a PR template update asking about them - as a first step?
The text was updated successfully, but these errors were encountered: