mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-15 12:51:30 -05:00
Merge pull request #5092 from tinganho/instanceOfElseClause
Instance of else clause
This commit is contained in:
@@ -6447,9 +6447,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(<Identifier>expr.left) !== symbol) {
|
||||
if (isTypeAny(type) || expr.left.kind !== SyntaxKind.Identifier || getResolvedSymbol(<Identifier>expr.left) !== symbol) {
|
||||
return type;
|
||||
}
|
||||
|
||||
// Check that right operand is a function type with a prototype property
|
||||
const rightType = checkExpression(expr.right);
|
||||
if (!isTypeSubtypeOf(rightType, globalFunctionType)) {
|
||||
@@ -6481,6 +6482,13 @@ namespace ts {
|
||||
}
|
||||
|
||||
if (targetType) {
|
||||
if (!assumeTrue) {
|
||||
if (type.flags & TypeFlags.Union) {
|
||||
return getUnionType(filter((<UnionType>type).types, t => !isTypeSubtypeOf(t, targetType)));
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
return getNarrowedType(type, targetType);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user