Redo in narrowing for intersections (#39637)

* Redo in-narrowing for intersections

Still need to carve out an exception for globalThis

* exempt globalThis from `in` narrowing
This commit is contained in:
Nathan Shively-Sanders
2020-07-30 14:58:22 -07:00
committed by GitHub
parent 32934a9989
commit d3877d294c
6 changed files with 72 additions and 6 deletions

View File

@@ -21475,7 +21475,9 @@ namespace ts {
}
function narrowByInKeyword(type: Type, literal: LiteralExpression, assumeTrue: boolean) {
if (type.flags & (TypeFlags.Union | TypeFlags.Object) || isThisTypeParameter(type)) {
if (type.flags & (TypeFlags.Union | TypeFlags.Object)
|| isThisTypeParameter(type)
|| type.flags & TypeFlags.Intersection && every((type as IntersectionType).types, t => t.symbol !== globalThisSymbol)) {
const propName = escapeLeadingUnderscores(literal.text);
return filterType(type, t => isTypePresencePossible(t, propName, assumeTrue));
}