Skip to content

Commit

Permalink
Preserve special intersections in mapped types
Browse files Browse the repository at this point in the history
  • Loading branch information
ahejlsberg committed Sep 9, 2022
1 parent 1a1c271 commit 014fc0e
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 014fc0e

Please sign in to comment.