Skip to content

Commit 84da19e

Browse files
authored
Add single-element fastpath to getSupertypeOrUnion (#43934)
1 parent 6f8c3b0 commit 84da19e

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

src/compiler/checker.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19954,6 +19954,9 @@ namespace ts {
1995419954
// of those literal types. Otherwise, return the leftmost type for which no type to the
1995519955
// right is a supertype.
1995619956
function getSupertypeOrUnion(types: Type[]): Type {
19957+
if (types.length === 1) {
19958+
return types[0];
19959+
}
1995719960
return literalTypesWithSameBaseType(types) ?
1995819961
getUnionType(types) :
1995919962
reduceLeft(types, (s, t) => isTypeSubtypeOf(s, t) ? t : s)!;

0 commit comments

Comments
 (0)