Add single-element fastpath to getSupertypeOrUnion (#43934)

This commit is contained in:
Wesley Wigham 2021-05-05 13:32:23 -07:00 committed by GitHub
parent 6f8c3b0c99
commit 84da19efc8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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)!;