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.

TS2769: No overload matches this call - emotion@11, emotion@10

See original GitHub issue

According to docs, it should be possible to style components with objects and functions - v10, v11

E.g.:

const theme = {
  bg: "#333",
  color: "white",
  p: "10px"
};

const base = ({ theme }) => ({
  color: theme.color,
  position: "absolute",
  top: "50%",
  left: "50%",
  transform: "translate(-50%, -50%)",
  border: "1px solid gray",
  fontFamily: "monospace"
});

const padding = ({ theme }) => ({
  padding: theme.p
});

const background = ({ theme }) => ({
  backgroundColor: theme.bg
});

const Text = styled("p")(base, padding, background);

But I’m getting the error at styled("p")(base, padding, background):

No overload matches this call.
  Overload 1 of 3, '(...styles: Interpolation<{ theme?: Theme | undefined; } & ClassAttributes<HTMLParagraphElement> & HTMLAttributes<HTMLParagraphElement> & { ...; } & { ...; }>[]): StyledComponent<...>', gave the following error.
    Argument of type '({ theme }: { theme: any; }) => { color: any; position: string; top: string; left: string; transform: string; border: string; fontFamily: string; }' is not assignable to parameter of type 'Interpolation<{ theme?: Theme | undefined; } & ClassAttributes<HTMLParagraphElement> & HTMLAttributes<HTMLParagraphElement> & { ...; } & { ...; }>'.
      Type '({ theme }: { theme: any; }) => { color: any; position: string; top: string; left: string; transform: string; border: string; fontFamily: string; }' is not assignable to type 'FunctionInterpolation<{ theme?: Theme | undefined; } & ClassAttributes<HTMLParagraphElement> & HTMLAttributes<HTMLParagraphElement> & { ...; } & { ...; }>'.
        Type '{ color: any; position: string; top: string; left: string; transform: string; border: string; fontFamily: string; }' is not assignable to type 'Interpolation<{ theme?: Theme | undefined; } & ClassAttributes<HTMLParagraphElement> & HTMLAttributes<HTMLParagraphElement> & { ...; } & { ...; }>'.
          Type '{ color: any; position: string; top: string; left: string; transform: string; border: string; fontFamily: string; }' is not assignable to type 'CSSObject'.
            Types of property 'position' are incompatible.
              Type 'string' is not assignable to type '"-moz-initial" | "inherit" | "initial" | "revert" | "unset" | "fixed" | "-webkit-sticky" | "absolute" | "relative" | "static" | "sticky" | PositionProperty[] | undefined'.
  Overload 2 of 3, '(template: TemplateStringsArray, ...styles: Interpolation<{ theme?: Theme | undefined; } & ClassAttributes<HTMLParagraphElement> & HTMLAttributes<...> & { ...; }>[]): StyledComponent<...>', gave the following error.
    Argument of type '({ theme }: { theme: any; }) => { color: any; position: string; top: string; left: string; transform: string; border: string; fontFamily: string; }' is not assignable to parameter of type 'TemplateStringsArray'.
      Type '({ theme }: { theme: any; }) => { color: any; position: string; top: string; left: string; transform: string; border: string; fontFamily: string; }' is missing the following properties from type 'TemplateStringsArray': raw, concat, join, slice, and 18 more.
  Overload 3 of 3, '(template: TemplateStringsArray, ...styles: Interpolation<{ theme?: Theme | undefined; } & ClassAttributes<HTMLParagraphElement> & HTMLAttributes<...> & { ...; } & { ...; }>[]): StyledComponent<...>', gave the following error.
    Argument of type '({ theme }: { theme: any; }) => { color: any; position: string; top: string; left: string; transform: string; border: string; fontFamily: string; }' is not assignable to parameter of type 'TemplateStringsArray'

Environment:

  • “react”: “16.13.1”
  • “typescript”: “3.9.3”

v11:

v10:

To reproduce:

Here’s a sandbox for v11. https://codesandbox.io/s/emotion11-ts2769-h0t4v

The issue is the same for v10.

Issue Analytics

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

github_iconTop GitHub Comments

3reactions
Andaristcommented, Jun 18, 2020

You must often type your object styles as CSSObject: https://codesandbox.io/s/emotion11-ts2769-m28iu?file=/src/index.tsx (or use const assertion)

This is related to TS’ “type widening” and you can read more about it here, here and here.

2reactions
Kif11commented, Jun 10, 2021

Is there any way to make this work with this?

const genericStyle = props => css`
    color: ${ props => props.color }
`

I keep getting this interpolation error on typescript whether I add CSSObject type or not.

Same problem. Pretty obscure error. Is there any solution? I tried to look for an exported CSS type under @emotion/react but no luck.

Read more comments on GitHub >

github_iconTop Results From Across the Web

No overload matches this call with styled components (index.d ...
The crux of the error is this: Type 'undefined' is not assignable to type 'ChangeEvent<HTMLInputElement>'. That is to say, in your Input ...
Read more >
Emotion 11
Emotion 11 is a slight evolution over the Emotion 10. It focuses mainly on the developer experience, TS types improvements, switches internals to...
Read more >
property 'css' does not exist on type 'intrinsicattributes - You.com
The type system is trying to match the properties with the first ... tsc --noEmit src/index.tsx:4:43 - error TS2769: No overload matches this...
Read more >
No overload matches this call with styled components ...
No overload matches this call in TypeScript is really annoying and there aren't too many solutions around there, though we have a solution!...
Read more >
No overload matches this call. TypeScript error while using ...
Property 'session' is missing in type 'NextApiRequest' but required in type 'AppSession'.ts(2769). No overload matches this call. Overload 1 ...
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