@@ -21218,29 +21218,26 @@ namespace ts {
21218
21218
}
21219
21219
return literalTypesWithSameBaseType(types) ?
21220
21220
getUnionType(types) :
21221
- reduceLeft(types, (s, t) => isTypeSubtypeOf(s, t ) ? t : s)!;
21221
+ reduceLeft(types, (s, t) => isTypeSubtypeOf(getNonNullableTypeIfNeeded(s), getNonNullableTypeIfNeeded(t) ) ? t : s)!;
21222
21222
}
21223
21223
21224
21224
function getCommonSupertype(types: Type[]): Type {
21225
21225
if (!strictNullChecks) {
21226
21226
return getSupertypeOrUnion(types);
21227
21227
}
21228
- const primaryTypes = filter(types, t => !(t.flags & TypeFlags.Nullable));
21229
- if (primaryTypes.length) {
21230
- const supertypeOrUnion = getSupertypeOrUnion(primaryTypes);
21231
- const supertypeOrUnionFacts = getTypeFacts(supertypeOrUnion);
21232
- const allFacts = getAllTypeFacts(types);
21233
21228
21234
- let missingNullableFlags: TypeFlags = 0;
21235
- if (allFacts & TypeFacts.IsNull && !(supertypeOrUnionFacts & TypeFacts.IsNull)) {
21236
- missingNullableFlags |= TypeFlags.Null;
21237
- }
21238
- if (allFacts & TypeFacts.IsUndefined && !(supertypeOrUnionFacts & TypeFacts.IsUndefined)) {
21239
- missingNullableFlags |= TypeFlags.Undefined;
21240
- }
21241
- return getNullableType(supertypeOrUnion, missingNullableFlags);
21229
+ const supertypeOrUnion = getSupertypeOrUnion(types);
21230
+ const supertypeOrUnionFacts = getTypeFacts(supertypeOrUnion);
21231
+ const allFacts = getAllTypeFacts(types);
21232
+
21233
+ let missingNullableFlags: TypeFlags = 0;
21234
+ if (allFacts & TypeFacts.IsNull && !(supertypeOrUnionFacts & TypeFacts.IsNull)) {
21235
+ missingNullableFlags |= TypeFlags.Null;
21236
+ }
21237
+ if (allFacts & TypeFacts.IsUndefined && !(supertypeOrUnionFacts & TypeFacts.IsUndefined)) {
21238
+ missingNullableFlags |= TypeFlags.Undefined;
21242
21239
}
21243
- return getUnionType(types, UnionReduction.Subtype );
21240
+ return getNullableType(supertypeOrUnion, missingNullableFlags );
21244
21241
}
21245
21242
21246
21243
// Return the leftmost type for which no type to the right is a subtype.
0 commit comments