diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 40db300d310..3dc9ee68d14 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -6362,9 +6362,10 @@ namespace ts { function narrowTypeByInstanceof(type: Type, expr: BinaryExpression, assumeTrue: boolean): Type { // Check that type is not any, assumed result is true, and we have variable symbol on the left - if (isTypeAny(type) || !assumeTrue || expr.left.kind !== SyntaxKind.Identifier || getResolvedSymbol(expr.left) !== symbol) { + if (isTypeAny(type) || expr.left.kind !== SyntaxKind.Identifier || getResolvedSymbol(expr.left) !== symbol) { return type; } + // Check that right operand is a function type with a prototype property let rightType = checkExpression(expr.right); if (!isTypeSubtypeOf(rightType, globalFunctionType)) { @@ -6396,6 +6397,13 @@ namespace ts { } if (targetType) { + if (!assumeTrue) { + if (type.flags & TypeFlags.Union) { + return getUnionType(filter((type).types, t => !isTypeSubtypeOf(t, targetType))); + } + return type; + } + return getNarrowedType(type, targetType); }