Preserve special intersections in mapped types (#50704)

* Preserve special intersections in mapped types

* Add regression test
This commit is contained in:
Anders Hejlsberg
2022-09-09 12:09:50 -07:00
committed by GitHub
parent 1a1c271675
commit a70bb9d3ff
6 changed files with 158 additions and 0 deletions

View File

@@ -11780,6 +11780,12 @@ namespace ts {
return mapType(type as UnionType, getLowerBoundOfKeyType);
}
if (type.flags & TypeFlags.Intersection) {
// Similarly to getTypeFromIntersectionTypeNode, we preserve the special string & {}, number & {},
// and bigint & {} intersections that are used to prevent subtype reduction in union types.
const types = (type as IntersectionType).types;
if (types.length === 2 && !!(types[0].flags & (TypeFlags.String | TypeFlags.Number | TypeFlags.BigInt)) && types[1] === emptyTypeLiteralType) {
return type;
}
return getIntersectionType(sameMap((type as UnionType).types, getLowerBoundOfKeyType));
}
return type;