react-codemod
react-codemod copied to clipboard
fix(remove-forward-ref): preserve union and intersection types
Previously, the codemod would drop union (|) and intersection (&) types from props when transforming forwardRef components, leaving components without proper type annotations:
// Before:
const Component = React.forwardRef<
HTMLElement,
{ someProp: boolean } & { anotherProp: number }>(
(props, ref) => ...
)
// Expected “after”:
const Component = (
{
ref,
...props
}:
{ someProp: boolean }
& { anotherProp: number }
& { ref: React.RefObject<HTMLDivElement> }) => ...
// Actual “after”: types completely missing:
const Component = (
{
ref,
...props
}) => ...
This PR fixes this, adding proper support for union and intersection types.