Skip to content

Commit 508cde0

Browse files
Andymhegazy
Andy
authored andcommitted
Document assignment to aliasSymbol in getUnionTypeFromSortedList (#17434)
* Document assignment to aliasSymbol in getUnionTypeFromSortedList * Update wording
1 parent 448d75c commit 508cde0

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/compiler/checker.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -7435,6 +7435,12 @@ namespace ts {
74357435
type = <UnionType>createType(TypeFlags.Union | propagatedFlags);
74367436
unionTypes.set(id, type);
74377437
type.types = types;
7438+
/*
7439+
Note: This is the alias symbol (or lack thereof) that we see when we first encounter this union type.
7440+
For aliases of identical unions, eg `type T = A | B; type U = A | B`, the symbol of the first alias encountered is the aliasSymbol.
7441+
(In the language service, the order may depend on the order in which a user takes actions, such as hovering over symbols.)
7442+
It's important that we create equivalent union types only once, so that's an unfortunate side effect.
7443+
*/
74387444
type.aliasSymbol = aliasSymbol;
74397445
type.aliasTypeArguments = aliasTypeArguments;
74407446
}
@@ -7528,7 +7534,7 @@ namespace ts {
75287534
type = <IntersectionType>createType(TypeFlags.Intersection | propagatedFlags);
75297535
intersectionTypes.set(id, type);
75307536
type.types = typeSet;
7531-
type.aliasSymbol = aliasSymbol;
7537+
type.aliasSymbol = aliasSymbol; // See comment in `getUnionTypeFromSortedList`.
75327538
type.aliasTypeArguments = aliasTypeArguments;
75337539
}
75347540
return type;

0 commit comments

Comments
 (0)