question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
strasscommented, Mar 30, 2021

did it work @strass 👀

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

1reaction
chaancecommented, Mar 30, 2021

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found