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.

Type Error with TypeScript 3.8.2 and theme 🏷

See original GitHub issue

Current behavior:

After updating typescript to 3.8.2 I’ve got an error with the theme. If a styled component uses the theme from the props the typescripts throw an error where I import and use the styled-component. The error tells that I don’t pass the theme in the styled-component. Error: 'theme' is declared here.

To reproduce:

  1. Update TS to 3.8.2
  2. Create a styled-component and use the theme from props
  3. Implement the styled-component
  4. Check the type error

Expected behavior:

The styled-component shouldn’t expect the theme where we plan to use it.

If I make the theme here an optional parameter here the error dissolves but It creates another error because theme becomes an optional parameter. I think the theme should be omitted in this file, maybe that would solve the issue.

Environment information:

  • react version: 16.9.0
  • emotion version: 10.0.27
  • typescript version: 3.8.2

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:6
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
aaronjensencommented, Mar 5, 2020

PR with fix here: https://github.com/emotion-js/emotion/pull/1788

If you’re a patch-package user:

patches/@emotion+styled-base+10.0.28.patch

diff --git a/node_modules/@emotion/styled-base/types/index.d.ts b/node_modules/@emotion/styled-base/types/index.d.ts
index 52dfe2f..6d7bd61 100644
--- a/node_modules/@emotion/styled-base/types/index.d.ts
+++ b/node_modules/@emotion/styled-base/types/index.d.ts
@@ -39,7 +39,7 @@ export interface StyledOptions {
 }
 
 export interface StyledComponent<InnerProps, StyleProps, Theme extends object>
-  extends React.SFC<InnerProps & StyleProps & { theme?: Theme }>,
+  extends React.SFC<InnerProps & Omit<StyleProps, 'theme'> & { theme?: Theme }>,
     ComponentSelector {
   /**
    * @desc this method is type-unsafe
3reactions
Andaristcommented, Mar 13, 2020

Thank you @Js-Brecht for the repro - I was able to test bunch of stuff using it. And thank you @aaronjensen for the fix.

I should release the fix by the end of the weekend.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Announcing TypeScript 3.8 - Microsoft Developer Blogs
This type-checking can tell us about errors like typos and values that are potentially null and undefined before we even run our code....
Read more >
Documentation - TypeScript 3.8
TypeScript 3.8 adds a new syntax for type-only imports and exports. ... error! A type-only import can specify a default import or named...
Read more >
React typescript '=' expected. TS1005 - Stack Overflow
Apologies, I misread it as an attempt to import a variable named type from ./types. What does your tsconfig look like? – Connor...
Read more >
TypeScript Compiling with Visual Studio Code
log ) in our TypeScript file, we may get the following output from tsc : HelloWorld.ts(3,17): error TS2339: Property 'logg' does not exist...
Read more >
TypeScript | WebStorm Documentation - JetBrains
icon. TypeScript-aware coding assistance includes completion for keywords, labels, variables, parameters, and functions, error and syntax ...
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