forwardRefWithAs in Typescript 4.2
See original GitHub issue🐛 Bug report
Keeping this brief and more as a heads up rather than a report since 4.2 just released 2 days ago. My team tried to upgrade and our components that used forwardRefWithAs broke.
Note: we aren’t using reach-ui, just your forwardRefWithAs hack
Current Behavior
After upgrading to Typescript 4.2 forwardRefWithAs has stopped working and components using as get this tsc error Expression produces a union type that is too complex to represent.
If we set as={asProp as 'div'}
on the component then the error goes away, so I think the default type of React.ElementType<any> is now causing issues.
Expected behavior
forwardRefWithAs is usable with future versions of Typescript
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:6 (3 by maintainers)
Top Results From Across the Web
forwardRefWithAs in Typescript 4.2 · Issue #753 · reach/reach-ui
After upgrading to Typescript 4.2 forwardRefWithAs has stopped working and components using as get this tsc error Expression produces a ...
Read more >Documentation - TypeScript 4.2
TypeScript has a way to declare new names for types called type aliases. If you're writing a set of functions that all work...
Read more >Announcing TypeScript 4.2 - Microsoft Developer Blogs
TypeScript has a way to declare new names for types called type aliases. If you're writing a set of functions that all work...
Read more >typescript - npm
TypeScript icon, indicating that this package has built-in type declarations. 4.2.2 • Public • Published 2 years ago.
Read more >Typescript 4.2 Released, Improves Types and Developer ...
The TypeScript team announced the release of TypeScript 4.2, which features more flexible type annotations, stricter checks, ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yeah, it was a shockingly easy conversion. We converted about 16 components of varying complexity from forward ref with as in less than a day
This should hopefully be addressed in the next release. I’ve removed the utility and simplified typing a bit. See notes in https://github.com/reach/reach-ui/commit/fb6ad2077c8b9d5fd6c476ad2efbec60f518443f