Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
19 changes: 19 additions & 0 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5446,7 +5446,26 @@ namespace ts {
return false;
}

function isSetOfLiteralsFromSameEnum(types: TypeSet): boolean {
const first = types[0];
if (first.flags & TypeFlags.EnumLiteral) {
const firstEnum = getParentOfSymbol(first.symbol);
for (let i = 1; i < types.length; i++) {
const other = types[i];
if (!(other.flags & TypeFlags.EnumLiteral) || (firstEnum !== getParentOfSymbol(other.symbol))) {
return false;
}
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

you can propably cache this getParentOfSymbol(first.symbol)

return true;
}

return false;
}

function removeSubtypes(types: TypeSet) {
if (types.length === 0 || isSetOfLiteralsFromSameEnum(types)) {
return;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe extract this logic into a separate isSetOfLiteralsFromSameEnum function and call that here. Otherwise, looks good to me.

}
let i = types.length;
while (i > 0) {
i--;
Expand Down
Loading