Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7359,6 +7359,11 @@ namespace ts {
type = <UnionType>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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would write this line as

For aliases of identical unions, eg type T = A | B; type U = A | B, the symbol of the first alias encountered is the aliasSymbol.

This is technically true even for the language server, but "first alias encountered" depends on the order of actions by the user.

It's important that we create equivalent union types only once, so that's an unfortunate side effect.
*/
type.aliasSymbol = aliasSymbol;
type.aliasTypeArguments = aliasTypeArguments;
}
Expand Down Expand Up @@ -7452,7 +7457,7 @@ namespace ts {
type = <IntersectionType>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;
Expand Down