mskelton / ratchet

Codemod to convert React PropTypes to TypeScript types.
https://mskelton.dev/ratchet
ISC License
138 stars 14 forks source link

Interested in `forwardRef` support? #49

Closed acao closed 1 year ago

acao commented 2 years ago

This library worked for all of our class and function components, but I had to fork it to get forwardRef working - would you be interested in a PR that both helps with finding the componentName and placing the declaration?

I'm referring to this pattern:

interface ComponentProps {}

const Component = React.forwardRef<React.HTMLSomethingElement, ComponentProps>( () => { })

the tricky part is we can't easily determine for the user what type of element to use for the first type arg

mskelton commented 2 years ago

Yeah, this would be a great improvement! As for the element type, HTMLElement would probably be best, while not "correct" it is the closest to correct without assumptions which is my philosophy when building ratchet.

acao commented 2 years ago

@mskelton awesome! I have submitted a PR, I hope it's a good start