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
Although not originally mentioned in the laws of union types (#805), I would generally expect a union of types undergoing a transformation to be equivalent to the result of its constituents undergoing the same transformation (distributive law?).
TypeScript Version:2.5.0-dev.20170626, presumably any version from the introduction of union types
Code
typex=({a: 1}|{a: 2})['a'];// 1 | 2typey={[k: string]: 3}['a'];// 3typez=({a: 1}|{a: 2}|{[k: string]: 3})['a'];// ^ Property 'a' does not exist on type ...
Expected behavior: z: 1 | 2 | 3
Actual behavior: Property 'a' does not exist on type ...
The text was updated successfully, but these errors were encountered:
I've since found that distributivity is not generally guaranteed with unions. This would fail, for one, for operations such as checking whether a given union contains a certain key.
Nevertheless, I believe the above snippet to intuitively indicate a bug.
Although not originally mentioned in the laws of union types (#805), I would generally expect a union of types undergoing a transformation to be equivalent to the result of its constituents undergoing the same transformation (distributive law?).
TypeScript Version:
2.5.0-dev.20170626
, presumably any version from the introduction of union typesCode
Expected behavior:
z
:1 | 2 | 3
Actual behavior:
Property 'a' does not exist on type ...
The text was updated successfully, but these errors were encountered: