From 0f132cdb7f2907d5a338565fc3ab91cbad0de2ba Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Mon, 18 Jul 2016 17:14:14 -0700 Subject: [PATCH] Order union type constituents by type ID --- src/compiler/checker.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index c7983d634a5..641b96bf6c4 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -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);