From 8f460a8446e46b48815cd96a187b101e71f61cfb Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Mon, 3 May 2021 12:46:44 -0700 Subject: [PATCH] Add single-element fastpath to getSupertypeOrUnion --- src/compiler/checker.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 4d95f128b1a0d..7225159484145 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -19954,6 +19954,9 @@ namespace ts { // of those literal types. Otherwise, return the leftmost type for which no type to the // right is a supertype. function getSupertypeOrUnion(types: Type[]): Type { + if (types.length === 1) { + return types[0]; + } return literalTypesWithSameBaseType(types) ? getUnionType(types) : reduceLeft(types, (s, t) => isTypeSubtypeOf(s, t) ? t : s)!;