@@ -8405,8 +8405,10 @@ namespace ts {
8405
8405
}
8406
8406
8407
8407
function isEmptyArrayAssignment(node: VariableDeclaration | BindingElement | Expression) {
8408
- return node.kind === SyntaxKind.VariableDeclaration && (<VariableDeclaration>node).initializer && isEmptyArrayLiteral((<VariableDeclaration>node).initializer) ||
8409
- node.kind !== SyntaxKind.BindingElement && node.parent.kind === SyntaxKind.BinaryExpression && isEmptyArrayLiteral((<BinaryExpression>node.parent).right);
8408
+ return node.kind === SyntaxKind.VariableDeclaration && (<VariableDeclaration>node).initializer &&
8409
+ isEmptyArrayLiteral((<VariableDeclaration>node).initializer) ||
8410
+ node.kind !== SyntaxKind.BindingElement && node.parent.kind === SyntaxKind.BinaryExpression &&
8411
+ isEmptyArrayLiteral((<BinaryExpression>node.parent).right);
8410
8412
}
8411
8413
8412
8414
function getReferenceCandidate(node: Expression): Expression {
@@ -8562,12 +8564,12 @@ namespace ts {
8562
8564
getUnionType(sameMap(types, finalizeEvolvingArrayType), subtypeReduction);
8563
8565
}
8564
8566
8565
- // Return true if the given node is 'x' in an 'x.push(value)' operation.
8566
- function isPushCallTarget (node: Node) {
8567
+ // Return true if the given node is 'x' in an 'x.push(value)' or 'x.unshift(value)' operation.
8568
+ function isPushOrUnshiftCallTarget (node: Node) {
8567
8569
const parent = getReferenceRoot(node).parent;
8568
8570
return parent.kind === SyntaxKind.PropertyAccessExpression &&
8569
- (<PropertyAccessExpression> parent).name.text === "push" &&
8570
- parent.parent.kind === SyntaxKind.CallExpression ;
8571
+ parent.parent.kind === SyntaxKind.CallExpression &&
8572
+ isPushOrUnshiftIdentifier((<PropertyAccessExpression> parent).name) ;
8571
8573
}
8572
8574
8573
8575
// Return true if the given node is 'x' in an 'x[n] = value' operation, where 'n' is an
@@ -8596,9 +8598,9 @@ namespace ts {
8596
8598
const evolvedType = getTypeFromFlowType(getTypeAtFlowNode(reference.flowNode));
8597
8599
visitedFlowCount = visitedFlowStart;
8598
8600
// When the reference is 'x' in an 'x.push(value)' or 'x[n] = value' operation, we give type
8599
- // 'any[]' to 'x' instead of using the type determed by control flow analysis such that new
8601
+ // 'any[]' to 'x' instead of using the type determined by control flow analysis such that new
8600
8602
// element types are not considered errors.
8601
- const isEvolvingArrayInferenceTarget = isEvolvingArrayType(evolvedType) && (isPushCallTarget (reference) || isElementAssignmentTarget(reference));
8603
+ const isEvolvingArrayInferenceTarget = isEvolvingArrayType(evolvedType) && (isPushOrUnshiftCallTarget (reference) || isElementAssignmentTarget(reference));
8602
8604
const resultType = isEvolvingArrayInferenceTarget ? anyArrayType : finalizeEvolvingArrayType(evolvedType);
8603
8605
if (reference.parent.kind === SyntaxKind.NonNullExpression && getTypeWithFacts(resultType, TypeFacts.NEUndefinedOrNull).flags & TypeFlags.Never) {
8604
8606
return declaredType;
0 commit comments