@@ -30866,23 +30866,18 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
3086630866 const parent = declaration.parent.parent;
3086730867 const rootDeclaration = getRootDeclaration(parent);
3086830868 if (rootDeclaration.kind === SyntaxKind.VariableDeclaration && getCombinedNodeFlagsCached(rootDeclaration) & NodeFlags.Constant || rootDeclaration.kind === SyntaxKind.Parameter) {
30869- const links = getNodeLinks(parent);
30870- if (!(links.flags & NodeCheckFlags.InCheckIdentifier)) {
30871- links.flags |= NodeCheckFlags.InCheckIdentifier;
30872- const parentType = getTypeForBindingElementParent(parent, CheckMode.Normal);
30873- const parentTypeConstraint = parentType && mapType(parentType, getBaseConstraintOrType);
30874- links.flags &= ~NodeCheckFlags.InCheckIdentifier;
30875- if (parentTypeConstraint && parentTypeConstraint.flags & TypeFlags.Union && !(rootDeclaration.kind === SyntaxKind.Parameter && isSomeSymbolAssigned(rootDeclaration))) {
30876- const pattern = declaration.parent;
30877- const narrowedType = getFlowTypeOfReference(pattern, parentTypeConstraint, parentTypeConstraint, /*flowContainer*/ undefined, location.flowNode);
30878- if (narrowedType.flags & TypeFlags.Never) {
30879- return neverType;
30880- }
30881- // Destructurings are validated against the parent type elsewhere. Here we disable tuple bounds
30882- // checks because the narrowed type may have lower arity than the full parent type. For example,
30883- // for the declaration [x, y]: [1, 2] | [3], we may have narrowed the parent type to just [3].
30884- return getBindingElementTypeFromParentType(declaration, narrowedType, /*noTupleBoundsCheck*/ true);
30869+ const parentType = getTypeForBindingElementParent(parent, CheckMode.Normal);
30870+ const parentTypeConstraint = parentType && mapType(parentType, getBaseConstraintOrType);
30871+ if (parentTypeConstraint && parentTypeConstraint.flags & TypeFlags.Union && !(rootDeclaration.kind === SyntaxKind.Parameter && isSomeSymbolAssigned(rootDeclaration))) {
30872+ const pattern = declaration.parent;
30873+ const narrowedType = getFlowTypeOfReference(pattern, parentTypeConstraint, parentTypeConstraint, /*flowContainer*/ undefined, location.flowNode);
30874+ if (narrowedType.flags & TypeFlags.Never) {
30875+ return neverType;
3088530876 }
30877+ // Destructurings are validated against the parent type elsewhere. Here we disable tuple bounds
30878+ // checks because the narrowed type may have lower arity than the full parent type. For example,
30879+ // for the declaration [x, y]: [1, 2] | [3], we may have narrowed the parent type to just [3].
30880+ return getBindingElementTypeFromParentType(declaration, narrowedType, /*noTupleBoundsCheck*/ true);
3088630881 }
3088730882 }
3088830883 }
0 commit comments