Don't narrow against unions of constructor functions with instanceof (#38099)

* WIP

* Only narrows when the union is not all constructors
This commit is contained in:
Orta Therox
2020-07-07 11:34:10 -04:00
committed by GitHub
parent 9a65658b28
commit 6ebd73c84f
5 changed files with 237 additions and 0 deletions

View File

@@ -21800,6 +21800,12 @@ namespace ts {
emptyObjectType;
}
// We can't narrow a union based off instanceof without negated types see #31576 for more info
if (!assumeTrue && rightType.flags & TypeFlags.Union) {
const nonConstructorTypeInUnion = find((<UnionType>rightType).types, (t) => !isConstructorType(t));
if (!nonConstructorTypeInUnion) return type;
}
return getNarrowedType(type, targetType, assumeTrue, isTypeDerivedFrom);
}