Skip to content

Conversation

ggascoigne
Copy link
Contributor

Using a combination of forwardRefs and generics leads to wanting to use type assertions to retain the generic nature of the wrapped class. This plays rather poorly with propTypes. After a lot of mucking around I decided to simply assert the desired type when setting propTypes and defaults.

This leads to code like this:

(MenuItem as ComponentObjectOf<typeof MenuItem>).propTypes - {...}

This change extends expressionTo.toArray to deal with the typescript expression.

Using a combination of forwardRefs and generics leads to wanting to use type assertions to retain the generic nature of the wrapped class.  This plays rather poorly with propTypes.  After a lot of mucking around I decided to simply assert the desired type when setting propTypes and defaults.

 This leads to code like this:

 ```tsx
 (MenuItem as ComponentObjectOf<typeof MenuItem>).propTypes - {...}
 ```

 This change extends expressionTo.toArray to deal with the typescript expression.
@danez danez merged commit 51e56b6 into reactjs:main Jul 2, 2022
danez added a commit that referenced this pull request Jul 2, 2022
…ions (#634)

Using a combination of forwardRefs and generics leads to wanting to use type assertions to retain the generic nature of the wrapped class.  This plays rather poorly with propTypes.  After a lot of mucking around I decided to simply assert the desired type when setting propTypes and defaults.

 This leads to code like this:

 ```tsx
 (MenuItem as ComponentObjectOf<typeof MenuItem>).propTypes - {...}
 ```

 This change extends expressionTo.toArray to deal with the typescript expression.

Co-authored-by: Daniel Tschinder <[email protected]>
# Conflicts:
#	src/__tests__/__snapshots__/main-test.js.snap
#	src/utils/__tests__/expressionTo-test.ts
@danez danez mentioned this pull request Jul 2, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 6, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants