Skip to content

Commit d702b0d

Browse files
committed
Cache the regularized form of union types
1 parent 78a9924 commit d702b0d

6 files changed

+50113
-1
lines changed

src/compiler/checker.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13457,9 +13457,13 @@ namespace ts {
1345713457
return type;
1345813458
}
1345913459

13460+
function getRegularTypeOfUnion(type: UnionType) {
13461+
return type.regularType || (type.regularType = getUnionType(sameMap((<UnionType>type).types, getRegularTypeOfLiteralType)) as UnionType);
13462+
}
13463+
1346013464
function getRegularTypeOfLiteralType(type: Type): Type {
1346113465
return type.flags & TypeFlags.Literal ? (<LiteralType>type).regularType :
13462-
type.flags & TypeFlags.Union ? getUnionType(sameMap((<UnionType>type).types, getRegularTypeOfLiteralType)) :
13466+
type.flags & TypeFlags.Union ? getRegularTypeOfUnion(<UnionType>type) :
1346313467
type;
1346413468
}
1346513469

src/compiler/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4651,6 +4651,8 @@ namespace ts {
46514651
export interface UnionType extends UnionOrIntersectionType {
46524652
/* @internal */
46534653
resolvedReducedType: Type;
4654+
/* @internal */
4655+
regularType: UnionType;
46544656
}
46554657

46564658
export interface IntersectionType extends UnionOrIntersectionType {

0 commit comments

Comments
 (0)