Allow assignments to a narrowable reference to be considered narrowable

This commit is contained in:
Ron Buckton
2020-07-29 16:37:11 -07:00
parent 03b658035d
commit b9db6413bf
7 changed files with 124 additions and 24 deletions

View File

@@ -837,7 +837,8 @@ namespace ts {
function isNarrowableReference(expr: Expression): boolean {
return expr.kind === SyntaxKind.Identifier || expr.kind === SyntaxKind.ThisKeyword || expr.kind === SyntaxKind.SuperKeyword ||
(isPropertyAccessExpression(expr) || isNonNullExpression(expr) || isParenthesizedExpression(expr)) && isNarrowableReference(expr.expression) ||
isElementAccessExpression(expr) && isStringOrNumericLiteralLike(expr.argumentExpression) && isNarrowableReference(expr.expression);
isElementAccessExpression(expr) && isStringOrNumericLiteralLike(expr.argumentExpression) && isNarrowableReference(expr.expression) ||
isAssignmentExpression(expr) && isNarrowableReference(expr.left);
}
function containsNarrowableReference(expr: Expression): boolean {

View File

@@ -20131,6 +20131,11 @@ namespace ts {
case SyntaxKind.ParenthesizedExpression:
case SyntaxKind.NonNullExpression:
return isMatchingReference(source, (target as NonNullExpression | ParenthesizedExpression).expression);
case SyntaxKind.BinaryExpression:
if (isAssignmentExpression(target)) {
return isMatchingReference(source, target.left);
}
break;
}
switch (source.kind) {
case SyntaxKind.Identifier: