Open nat-foo opened 4 months ago
Confirmed https://codesandbox.io/p/sandbox/wizardly-kapitsa-forked-7lcnhc?file=%2Fsrc%2FApp.tsx%3A11%2C1
Seems like the type is incorrectly widening, maybe because Props
defaults to object
.
Yes, we've noticed this too on v6 that any property of theme
is allowed.
// computed type of our custom theme:
const theme: {
[x: string]: any; // any property is allowed incorrectly
// all the other valid properties that still benefit from autocomplete
}
const Test = styled.div`
color: ${({ theme }) => theme.gibberish.properties.that.dont.exist}; // incorrect types are OK
`;
Environment
npx envinfo --system --binaries --npmPackages styled-components,babel-plugin-styled-components --markdown
System:
Binaries:
npmPackages:
Reproduction
Code Sandbox Reproduction
Steps to reproduce
Expected Behavior
Overriding the DefaultTheme interface in the way the docs provide (and in the type declaration for DefaultTheme itself) should result in being able to access the custom theme type when using
styled.div
${(props) => props.theme.etc}`.Actual Behavior
It does not. Only the ThemeProvider seems to benefit from the custom typing.
Thanks for your time!