From 014fc0e1eb3885bccf64b59abd641bc7c09fce78 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Fri, 9 Sep 2022 11:29:50 -0700 Subject: [PATCH] Preserve special intersections in mapped types --- src/compiler/checker.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 6da3c9e760c3f..862fb23fa361e 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -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;