From abfeac9e2e6b0b090dcdecc850e461d93d280dc4 Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Wed, 26 Jul 2017 13:28:10 -0700 Subject: [PATCH 1/2] Document assignment to aliasSymbol in getUnionTypeFromSortedList --- src/compiler/checker.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 2ff45ee0b737d..c4c384a7c4ad7 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -7359,6 +7359,11 @@ namespace ts { type = createType(TypeFlags.Union | propagatedFlags); unionTypes.set(id, type); type.types = types; + /* + Note: This is the alias symbol (or lack thereof) that we see when we first encounter this union type. + If there exist both `type T = number | boolean` and `type U = number | boolean`, it is arbitrary which one gets the aliasSymbol. + It's important that we create equivalent union types only once, so that's an unfortunate side effect. + */ type.aliasSymbol = aliasSymbol; type.aliasTypeArguments = aliasTypeArguments; } @@ -7452,7 +7457,7 @@ namespace ts { type = createType(TypeFlags.Intersection | propagatedFlags); intersectionTypes.set(id, type); type.types = typeSet; - type.aliasSymbol = aliasSymbol; + type.aliasSymbol = aliasSymbol; // See comment in `getUnionTypeFromSortedList`. type.aliasTypeArguments = aliasTypeArguments; } return type; From bb29f976509c07dd0491191271777713ff110b78 Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Tue, 29 Aug 2017 09:40:47 -0700 Subject: [PATCH 2/2] Update wording --- src/compiler/checker.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index c4c384a7c4ad7..a84d224b4d397 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -7361,7 +7361,8 @@ namespace ts { type.types = types; /* Note: This is the alias symbol (or lack thereof) that we see when we first encounter this union type. - If there exist both `type T = number | boolean` and `type U = number | boolean`, it is arbitrary which one gets the aliasSymbol. + For aliases of identical unions, eg `type T = A | B; type U = A | B`, the symbol of the first alias encountered is the aliasSymbol. + (In the language service, the order may depend on the order in which a user takes actions, such as hovering over symbols.) It's important that we create equivalent union types only once, so that's an unfortunate side effect. */ type.aliasSymbol = aliasSymbol;