From 8a0bc3b992328adc2fd40efb52d7f0d1d81c3604 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Thu, 21 Apr 2016 13:02:52 -0700 Subject: [PATCH] Support assignments in truthiness type guards --- src/compiler/binder.ts | 2 ++ src/compiler/checker.ts | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 91f4247a673..3d6db01580a 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -617,6 +617,8 @@ namespace ts { function isNarrowingBinaryExpression(expr: BinaryExpression) { switch (expr.operatorToken.kind) { + case SyntaxKind.EqualsToken: + return isNarrowableReference(expr.left); case SyntaxKind.EqualsEqualsToken: case SyntaxKind.ExclamationEqualsToken: case SyntaxKind.EqualsEqualsEqualsToken: diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 195245648a7..a3b3451fe35 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -7671,6 +7671,8 @@ namespace ts { function narrowTypeByBinaryExpression(type: Type, expr: BinaryExpression, assumeTrue: boolean): Type { switch (expr.operatorToken.kind) { + case SyntaxKind.EqualsToken: + return narrowTypeByTruthiness(type, expr.left, assumeTrue); case SyntaxKind.EqualsEqualsToken: case SyntaxKind.ExclamationEqualsToken: case SyntaxKind.EqualsEqualsEqualsToken: