react-codemod icon indicating copy to clipboard operation
react-codemod copied to clipboard

fix(remove-forward-ref): preserve union and intersection types

Open iamakulov opened this issue 5 months ago • 1 comments

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.

iamakulov avatar Aug 19 '25 01:08 iamakulov