Skip to content

Conversation

iamakulov
Copy link

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.

Previously, the codemod would drop union (|) and intersection (&) types
from props when transforming forwardRef components, leaving components
without proper type annotations.

Now supports:
- Union types: ButtonProps | LinkProps
- Intersection types: BaseProps & MetaProps
- Complex nested combinations

Example transformation:
```typescript
// Before
React.forwardRef<HTMLElement, BaseProps & MetaProps>((props, ref) => ...)

// After
({ ref, ...props }: BaseProps & MetaProps & { ref: React.RefObject<HTMLElement> }) => ...
```

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@iamakulov
Copy link
Author

iamakulov commented Aug 19, 2025

(Note: these tests will need to be updated a bit (refref?) if #338 lands.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant