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.

Can't use `as` prop when using TypeScript

See original GitHub issue

Current behavior:

The as prop cannot be used when using TypeScript. I’m using babel + emotion plugin.

To reproduce: Example copied from the doc: https://emotion.sh/docs/styled#as-prop

Checkout this repository: ExampleComponent.tsx

image

Environment information:

  • typescript version: 4.1.5
  • react version: 17
  • @emotion/react version: 11

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:12
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
Andaristcommented, Aug 2, 2022

If I remember correctly many people were trying to solve this typing problem in various different libraries and it always came with a severe performance cost. If somebody solves it without degrading performance though - I would be open to merging a PR introducing this.

1reaction
LeunensMichielcommented, Mar 12, 2021

I solved it by using the withComponent tag. https://emotion.sh/docs/typescript#withcomponent

Although it is not ideal 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

react typescript with function passed as prop, but can't access
I want to practice some complex feature by passing function as prop to child component. I remember 'this.props' allows me to access all...
Read more >
Passing props in React using Typescript - DEV Community ‍ ‍
I've recently been working on a project and attempting to teach myself a bit of TypeScript as I go. It's been.... interesting, to...
Read more >
Documentation - Decorators - TypeScript
A Property Decorator is declared just before a property declaration. A property decorator cannot be used in a declaration file, or in any...
Read more >
Documentation - Everyday Types - TypeScript
The type names String , Number , and Boolean (starting with capital ... When a value is of type any , you can...
Read more >
Documentation - Classes - TypeScript
Just like with const , let , and var , the initializer of a class property will be used to infer its type:...
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