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.

Props don't work anymore with TypeScript 3.4.1

See original GitHub issue
  • emotion version: 10.0.10
  • react version: 16.8.6

Relevant code:

const Container = styled.div((props: { test: number }) => ({
  width: props.test,
}));

What you did:

Updated TypeScript to the latest version 3.4.1

What happened:

error TS2345: Argument of type '(props: { test: number; }) => { width: number; }' is not assignable to parameter of type 'TemplateStringsArray'.
  Type '(props: { test: number; }) => { width: number; }' is missing the following properties from type 'TemplateStringsArray': raw, concat, join, slice, and 16 more.

Reproduction:

Just create a fresh empty project with TypeScript and emotion and paste my code above into it. I can do that for you if you want, but it’s so simple to reproduce that I thought it is not necessary.

Problem description:

Does not compile anymore. With the TypeScript version before (3.3.4000) it worked.

Suggested solution:

Fix TypeScript definition.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:16
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

4reactions
skovhuscommented, Apr 11, 2019

And with the other syntax styled('div'), you can do:

styled('div')<{ test: number }>`...`
3reactions
Dudeonyxcommented, Apr 5, 2019

Solution:

const Container = styled.div<{ test: number }>((props) => ({
  width: props.test,
}));

✌️

Read more comments on GitHub >

github_iconTop Results From Across the Web

The Angular Compiler requires TypeScript >=3.4.0 and <3.5.0 ...
In my case, I had to use npm install typescript@">=3.4. 0 and <3.6. 0" --save-dev because the warning was showing the version interval...
Read more >
Documentation - TypeScript 3.4
TypeScript 3.4 can now produce generic function types when inference from other generic functions produces free type variables for inferences. This means many ......
Read more >
What's New in Typescript 3.4 - Medium
TypeScript is a programming language which builds on Javascript and provides optional static types. If you are not familiar with it please ...
Read more >
Announcing TypeScript 3.5 - Microsoft Developer Blogs
Today we're happy to announce the availability of TypeScript 3.5! If you're new to TypeScript, it's a language that builds on JavaScript ...
Read more >
Component prop types are not inferred when using styled ...
Currently WebStorm's own support for TypeScript doesn't see these props, but when the TypeScript service is enabled in the IDE (and it's on...
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