Skip to content

Commit ebb17e8

Browse files
authored
do not apply subtype reduction if type set contains enum literals fro… (microsoft#11368)
* do not apply subtype reduction if type set contains enum literals from the same enum * do not re-read symbol for the first enum * addressed PR feedback
1 parent f4dc114 commit ebb17e8

File tree

5 files changed

+23108
-0
lines changed

5 files changed

+23108
-0
lines changed

src/compiler/checker.ts

+19
Original file line numberDiff line numberDiff line change
@@ -5446,7 +5446,26 @@ namespace ts {
54465446
return false;
54475447
}
54485448

5449+
function isSetOfLiteralsFromSameEnum(types: TypeSet): boolean {
5450+
const first = types[0];
5451+
if (first.flags & TypeFlags.EnumLiteral) {
5452+
const firstEnum = getParentOfSymbol(first.symbol);
5453+
for (let i = 1; i < types.length; i++) {
5454+
const other = types[i];
5455+
if (!(other.flags & TypeFlags.EnumLiteral) || (firstEnum !== getParentOfSymbol(other.symbol))) {
5456+
return false;
5457+
}
5458+
}
5459+
return true;
5460+
}
5461+
5462+
return false;
5463+
}
5464+
54495465
function removeSubtypes(types: TypeSet) {
5466+
if (types.length === 0 || isSetOfLiteralsFromSameEnum(types)) {
5467+
return;
5468+
}
54505469
let i = types.length;
54515470
while (i > 0) {
54525471
i--;

0 commit comments

Comments
 (0)