mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-16 07:13:45 -05:00
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:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user