TS2769: No overload matches this call - emotion@11, emotion@10
See original GitHub issueAccording 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:
- “@emotion/react”: “11.0.0-next.12”
- “@emotion/styled”: “11.0.0-next.12”
v10:
- “@emotion/core”: “10.0.27”
- “@emotion/styled”: “10.0.27”
- “emotion-theming”: “10.0.27”
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:
- Created 3 years ago
- Reactions:6
- Comments:5 (1 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
You must often type your object styles as
CSSObject
: https://codesandbox.io/s/emotion11-ts2769-m28iu?file=/src/index.tsx (or useconst
assertion)This is related to TS’ “type widening” and you can read more about it here, here and here.
Same problem. Pretty obscure error. Is there any solution? I tried to look for an exported CSS type under
@emotion/react
but no luck.