Skip to content

Commit 014fc0e

Browse files
committed
Preserve special intersections in mapped types
1 parent 1a1c271 commit 014fc0e

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/compiler/checker.ts

+6
Original file line numberDiff line numberDiff line change
@@ -11780,6 +11780,12 @@ namespace ts {
1178011780
return mapType(type as UnionType, getLowerBoundOfKeyType);
1178111781
}
1178211782
if (type.flags & TypeFlags.Intersection) {
11783+
// Similarly to getTypeFromIntersectionTypeNode, we preserve the special string & {}, number & {},
11784+
// and bigint & {} intersections that are used to prevent subtype reduction in union types.
11785+
const types = (type as IntersectionType).types;
11786+
if (types.length === 2 && !!(types[0].flags & (TypeFlags.String | TypeFlags.Number | TypeFlags.BigInt)) && types[1] === emptyTypeLiteralType) {
11787+
return type;
11788+
}
1178311789
return getIntersectionType(sameMap((type as UnionType).types, getLowerBoundOfKeyType));
1178411790
}
1178511791
return type;

0 commit comments

Comments
 (0)