Order union type constituents by type ID

This commit is contained in:
Anders Hejlsberg
2016-07-18 17:14:14 -07:00
parent 32f4cbb58a
commit 0f132cdb7f

View File

@@ -5215,6 +5215,10 @@ namespace ts {
}
}
function compareTypeIds(type1: Type, type2: Type): number {
return type1.id - type2.id;
}
// We reduce the constituent type set to only include types that aren't subtypes of other types, unless
// the noSubtypeReduction flag is specified, in which case we perform a simple deduplication based on
// object identity. Subtype reduction is possible only when union types are known not to circularly
@@ -5234,6 +5238,7 @@ namespace ts {
if (typeSet.containsAny) {
return anyType;
}
typeSet.sort(compareTypeIds);
if (strictNullChecks) {
if (typeSet.containsNull) typeSet.push(nullType);
if (typeSet.containsUndefined) typeSet.push(undefinedType);