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:
Vladimir Matveev
2016-10-04 16:32:16 -07:00
committed by GitHub
parent f4dc11427f
commit ebb17e8019
5 changed files with 23108 additions and 0 deletions

View File

@@ -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--;