You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
interfaceTwoSameTypes<T>{a: T;b: T;}// @ts-expect-errorconstx : TwoSameTypes<Number|String>={a: 1,b: "string",// <-- This does not give an error, because `b` has the type `String | Number`}
π Actual behavior
No error happens
π Expected behavior
I would expect an error for the value of x because both a and b are expected to have the same type, but they don't in this case.
For the record, and as can be seen from the playground link, when doing TwoSameTypes<Number> | TwoSameTypes<String> instead of TwoSameTypes<Number | String> we do end up with the desired behaviour. But I think these two different ways of defining are equivalent? So it seems like the latter way of doing it should work as well.
Furthermore, here's demo of a use case for this behaviour. I would like to use keyof ValueMap as the generic type, so I don't have to type every possible enum twice.
Apologies in advance if this is a duplicate, I wasn't able to find the right keywords to describe this behaviour.
The text was updated successfully, but these errors were encountered:
a and b do have the same type though; and that type is number | string. TwoSameTypes<number> | TwoSameTypes<string> and TwoSameTypes<number | string> are not equivalent, and this is the difference.
Bug Report
π Search Terms
union generic implicit
π Version & Regression Information
β― Playground Link
Playground link with relevant code
π» Code
π Actual behavior
No error happens
π Expected behavior
I would expect an error for the value of
x
because botha
andb
are expected to have the same type, but they don't in this case.For the record, and as can be seen from the playground link, when doing
TwoSameTypes<Number> | TwoSameTypes<String>
instead ofTwoSameTypes<Number | String>
we do end up with the desired behaviour. But I think these two different ways of defining are equivalent? So it seems like the latter way of doing it should work as well.Furthermore, here's demo of a use case for this behaviour. I would like to use
keyof ValueMap
as the generic type, so I don't have to type every possible enum twice.Apologies in advance if this is a duplicate, I wasn't able to find the right keywords to describe this behaviour.
The text was updated successfully, but these errors were encountered: