-
Notifications
You must be signed in to change notification settings - Fork 12.3k
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
Union in template literal simplifying unexpectedly #58340
Comments
(There are no distributive conditional types in this issue) #48034 #48044 #49839 #54188 #54648 #56458 #57807 #57918 From previous issues having to do with branded primitives in template literals, it's not clear what the "correct" behavior should be here. Looks like different people have very different expectations. |
I can see how people might want it differently, but what if we wanted to intentionally distribute it? type Foo<T extends string> = T extends T ? `foo${T}` : never;
type FooN = Foo<`100` | `${number & {}}`>;
// FooN is still `foo${number & {}}` |
I don't know any good way to reason about this. Either |
Possibly if #33471 is ever implemented there would be a way to have this work also. The issue isnβt that the reduction is incorrect, but that it obscures information people want to keep around. |
@RyanCavanaugh I assume this to be the template-string analogue of type T = 1 | 2 | 3 | (number & {}); which is (IIUC, very much intentionally) not reduced today even though |
This issue has been marked as "Not a Defect" and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
π Search Terms
template literal union distributive conditional type
π Version & Regression Information
5.4.5 and Nightly
β― Playground Link
https://www.typescriptlang.org/play/?ts=5.4.5#code/C4TwDgpgBAYg9nAclAvFABgMwQEgN4DkAjAAwkFQA+UAFOvgHYCuAtgEYQBOAvulAGRQ83AJS8A3ACgA9NKihIsBMjRZceenmbsuvAUO68ZciAA9IAY2AQAJqigAibHFIkHVDM-ybtHHn0FhXiA
π» Code
π Actual behavior
'100'
and`${number}` & {}
are being simplified to`${number}` & {}
.FooN
does not have autocomplete for'foo100'
π Expected behavior
FooN
should be of type"foo100" | `foo${`${number}` & {}}
and provide autocomplete forfoo100
while allowingfoo101
or any other numberAdditional information about the issue
No response
The text was updated successfully, but these errors were encountered: