Replies: 1 comment 3 replies
-
I don't think this should result in an error because support for this has been implemented explicitly as a new feature for v11. Could you create a codesnadbox demonstrating the problem? Also, a bonus question: why do we have to type Theme manually when using the css prop? TypeScript complains about the parameter being implicitly any. const textColor = (theme: Theme) => css({
color: theme.colors.primary
});
const background = (theme: Theme) => css({
background: theme.colors.secondary
});
We can use these like this: <div css={textColor}></div> <div css={background}></div> However, if we want to apply both of them, this throws a TypeScript error: <div css={[textColor, background]}></div> Is this intentional? It feels a bit verbose to do the following: <div css={(theme: Theme) => [textColor(theme), background(theme)]}></div>
Do you refer to functions like this? const textColor = (theme: Theme) => css({
color: theme.colors.primary
}); It's really more of a TS question than Emotion's one - this is how TS works, this function doesn't have enough "context" for TS to infer its parameter types. It's a standalone function and as such all of its parameters have to be annotated explicitly, the same would apply here: const add = (a, b) => a + b In here TS can't assess on its own that |
Beta Was this translation helpful? Give feedback.
-
Hi! If we're making reusable CSS objects as a callback to access the theme:
We can use these like this:
However, if we want to apply both of them, this throws a TypeScript error:
Is this intentional? It feels a bit verbose to do the following:
Also, a bonus question: why do we have to type
Theme
manually when using thecss
prop? TypeScript complains about the parameter being implicitlyany
.Beta Was this translation helpful? Give feedback.
All reactions