do not apply subtype reduction if type set contains enum literals fro… (#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
This commit is contained in:
parent
f4dc11427f
commit
ebb17e8019
|
@ -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;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function removeSubtypes(types: TypeSet) {
|
||||
if (types.length === 0 || isSetOfLiteralsFromSameEnum(types)) {
|
||||
return;
|
||||
}
|
||||
let i = types.length;
|
||||
while (i > 0) {
|
||||
i--;
|
||||
|
|
4113
tests/baselines/reference/enumLiteralsSubtypeReduction.js
Normal file
4113
tests/baselines/reference/enumLiteralsSubtypeReduction.js
Normal file
File diff suppressed because it is too large
Load diff
7693
tests/baselines/reference/enumLiteralsSubtypeReduction.symbols
Normal file
7693
tests/baselines/reference/enumLiteralsSubtypeReduction.symbols
Normal file
File diff suppressed because it is too large
Load diff
9229
tests/baselines/reference/enumLiteralsSubtypeReduction.types
Normal file
9229
tests/baselines/reference/enumLiteralsSubtypeReduction.types
Normal file
File diff suppressed because it is too large
Load diff
2054
tests/cases/compiler/enumLiteralsSubtypeReduction.ts
Normal file
2054
tests/cases/compiler/enumLiteralsSubtypeReduction.ts
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue