-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
some types in 4.5.0 aren't correctly resolving to same types in 4.4.4 #46624
Comments
it seems that this line causes the discrepancy: export type Params<T extends kind> = { type?: T } & Options<T>; Changing this to: export type Params<T extends kind> = { type?: T }; Resolves both versions to the same type: |
The issue is we're seeing const result = getInterfaceFromString({ type: 'two' });
// { type?: kind } instead of const result = getInterfaceFromString({ type: 'two' });
// { type?: "two" } Using |
Unclear if fixing this in 4.5 will be possible without other breaking changes, but worth looking into. |
Note that both 4.5 and 4.4 say that the type is |
Broken by #46052 |
The surprising thing is that |
Ooo, this is a nasty little issue. During union type construction we repurpose certain |
Here's a simplified repro: export type Kind = "one" | "two" | "three";
declare function getInterfaceFromString<T extends Kind>(options?: { type?: T } & { type?: Kind }): T;
const result = getInterfaceFromString({ type: 'two' }); // Should be "two", not Kind |
Bug Report
I recently ran into the this strange error when I updated to typescript 4.5.0-beta, generic types that were resolving properly in 4.4.4, are not correctly resolving in 4.5.0-beta. Instead 4.5.0 returns a unions of all of the possible values while the same code in 4.4.4 returns a narrowed generic type.
🔎 Search Terms
4.5.0-beta, unions, generics
🕗 Version & Regression Information
typescript@beta, 4.5.0-beta, typescript@next
⏯ Playground Link
Same code for both versions:
Playground link with relevant code
💻 Code
🙁 Actual behavior
In typescript 4.4.4 the type is correctly resolved to
Two
, whereas in typescript 4.5.0 the type is resolved toOne | Two | Three
which is incorrect.4.4.4:
4.5.0-beta:
🙂 Expected behavior
The correct type for
result
in the playground and the codesample isTwo
, notOne | Two | Three
, typescript 4.5.0 should resolve to this type.The text was updated successfully, but these errors were encountered: