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
{{ message }}
Repository navigation
The behavior of the intersection type of array changed in 2.6.1 #20001
This is an effect of #18438. We now remove empty intersection types (i.e. intersection types for which no values exist) from union types. In your example, this means that undefined & (B & { c: C })[] is removed when constructing the type for bList, leaving just B[] & (B & { c: C })[]. Then, as we look for a map member on that type, we end up picking the candidate from B[] and therefore item has type B. Previously we'd pick a candidate from (B & { c: C })[] because we didn't remove the empty intersection.
In general, when the constituent types of intersections have overlapping signatures, the intersection is order sensitive because overload resolution processes the signatures from left to right. Indeed, your example works if you change the type of Q to list A last:
constQ: {bList: (B&{c: C})[]}&A={ ... };// Now works
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.
Activity
ahejlsberg commentedon Nov 15, 2017
This is an effect of #18438. We now remove empty intersection types (i.e. intersection types for which no values exist) from union types. In your example, this means that
undefined & (B & { c: C })[]is removed when constructing the type forbList, leaving justB[] & (B & { c: C })[]. Then, as we look for amapmember on that type, we end up picking the candidate fromB[]and thereforeitemhas typeB. Previously we'd pick a candidate from(B & { c: C })[]because we didn't remove the empty intersection.In general, when the constituent types of intersections have overlapping signatures, the intersection is order sensitive because overload resolution processes the signatures from left to right. Indeed, your example works if you change the type of
Qto listAlast:icepeng commentedon Nov 16, 2017
It would be nice to write that the intersection type is order sensitive in the advanced types section of the typescript handbook.
typescript-bot commentedon Dec 1, 2017
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.