mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-27 22:39:59 -05:00
Merge pull request #39824 from microsoft/fix35484
Allow assignments to a narrowable reference to be considered narrowable
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -20141,6 +20141,8 @@ namespace ts {
|
||||
case SyntaxKind.ParenthesizedExpression:
|
||||
case SyntaxKind.NonNullExpression:
|
||||
return isMatchingReference(source, (target as NonNullExpression | ParenthesizedExpression).expression);
|
||||
case SyntaxKind.BinaryExpression:
|
||||
return isAssignmentExpression(target) && isMatchingReference(source, target.left);
|
||||
}
|
||||
switch (source.kind) {
|
||||
case SyntaxKind.Identifier:
|
||||
|
||||
Reference in New Issue
Block a user