Open narwold opened 3 months ago
There are one difference between your gobal file. In the one you said that it works (v5) the globla file name is global.d.ts
and in the other one is global.ts
you need to specify it as a declaration file
There are one difference between your gobal file. In the one you said that it works (v5) the globla file name is
global.d.ts
and in the other one isglobal.ts
you need to specify it as a declaration file
I had already tried that locally several times; that seems to have nothing to do with it. The fact that there was an inconsistency in the sandboxes was accidental. You'll see I've now changed it, and it does not solve the problem.
Also, it is reading the global type properly, because it will show the correct types if I use a known field (notice that "legitColor" gets shown as a string in both cases). The problem is the extra index that is being mixed in from the original type, so in the v6 sandbox an unknown type shows up as "any" whereas in the v6 sandbox it errors out as it should.
Same issue as #4247
I don't think the original #4247 is the same issue (but the replies are), because it mentions not being able to benefit from types at all in a SC (only the ThemeProvider). That is not the symptom here, as I get the types just fine; they are just too broad because they contain the any
index.
Same issue here, Theme is typed via styled.d.ts
file, the added types are indeed present but typescript not limiting the type to the added keys, and any key can be passed.
It seems like falling back to the DefaultTheme inside node modules when key is not present in the provided type.
Environment
Reproduction
The previous DefinitelyTyped types used an empty object for DefaultTheme, which had the effect of allowing any keys until DefaultTheme was extended via https://styled-components.com/docs/api#create-a-declarations-file, at which time the theme ended up being strictly typed, and references to unknown keys threw an error in TS.
In the new v6 types, an index is being added (
[key: string]: any;
) that explicitly allows any key. There does not appear to be any way to remove/override this.Steps to reproduce
Expected Behavior
TS throws an error with unknown keys on the theme, if I have specified an explicit type for the theme via https://styled-components.com/docs/api#create-a-declarations-file
Actual Behavior
TS allows any key I want to reference, which does not enforce type safety on the theme.