Description
Related to: #2445
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 amemo
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?