The theme variable got the any type just on the top-level. If I'm using theme at a css'' block it got the correct typing DefaultTheme.
Example:
const Header = styled.div<{ invertedColor: boolean }>`
color: ${({ theme }) => theme.color.blue}; // theme = any
${({ invertedColor }) =>
invertedColor &&
css`
color: ${({ theme }) => theme.color.white}; // theme = DefaultTheme (correct)
`}
`
Also <{ invertedColor: boolean }> is not working since invertedColor is any here.
I've added a styled-components.d.ts with the following content:
import 'styled-components';
type ColorType = 'blue' | 'white';
declare module 'styled-components' {
export interface DefaultTheme {
color: Record<ColorType, string>;
}
}
Using the following versions:
"@types/styled-components": "^5.1.22",
"styled-components": "^5.3.3",
I've tried to debug & check where the type is lost because its correctly passed at the ThemeProvider - also tried every solution from here: https://github.com/styled-components/styled-components/issues/1589
What's the best way to debug that? Any hint?