Fixed narrowing based on aliased discriminants coming from destructured parameters (#56860)

This commit is contained in:
Mateusz Burzyński
2024-01-08 22:18:06 +01:00
committed by GitHub
parent 01a51d2d01
commit 5a355093bb
6 changed files with 118 additions and 3 deletions

View File

@@ -476,6 +476,7 @@ import {
isCallOrNewExpression,
isCallSignatureDeclaration,
isCatchClause,
isCatchClauseVariableDeclaration,
isCatchClauseVariableDeclarationOrBindingElement,
isCheckJsEnabledForFile,
isClassDeclaration,
@@ -27490,7 +27491,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
case SyntaxKind.ObjectBindingPattern:
case SyntaxKind.ArrayBindingPattern:
const rootDeclaration = getRootDeclaration(node.parent);
return isVariableDeclaration(rootDeclaration) && isVarConstLike(rootDeclaration);
return isParameter(rootDeclaration) || isCatchClauseVariableDeclaration(rootDeclaration)
? !isSomeSymbolAssigned(rootDeclaration)
: isVariableDeclaration(rootDeclaration) && isVarConstLike(rootDeclaration);
}
return false;
}