Skip to content

Align object binding defaults with arrays - #64043

Open
Jake Bailey (jakebailey) wants to merge 2 commits into
microsoft:mainfrom
jakebailey:fix-59920-2
Open

Align object binding defaults with arrays#64043
Jake Bailey (jakebailey) wants to merge 2 commits into
microsoft:mainfrom
jakebailey:fix-59920-2

Conversation

@jakebailey

Copy link
Copy Markdown
Member

Fixes #59920

Implements Anders' suggestion in #59920 (comment)

Object binding patterns with an object-literal parameter default only
added missing elements that had their own initializer. Array patterns
already add every missing element, so equivalent object and array
parameters inferred different types and produced different diagnostics.

Pad object literal defaults with every missing binding element in all
source kinds. Report implicit any through the existing diagnostic path,
which preserves normal checkJs suppression while making checked JS and
TypeScript match array patterns.

Add matrix coverage for object and array patterns in TypeScript, checked
JavaScript, and unchecked JavaScript.

Fixes microsoft#59920
Copilot AI balanced review requested due to automatic review settings August 26, 2026 22:55
@github-project-automation github-project-automation Bot moved this to Not started in PR Backlog Aug 26, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Aligns object-destructuring defaults with array behavior, addressing #59920.

Changes:

  • Pads missing object-binding properties as optional.
  • Reports implicit any consistently.
  • Adds compiler tests and baselines.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tsc/internal/checker/checker.go Updates object-binding type inference.
tsc/testdata/tests/cases/compiler/objectBindingPatternDefaultMissingElements.ts Adds regression coverage.
tsc/testdata/baselines/reference/compiler/objectBindingPatternDefaultMissingElements.types Records inferred types.
tsc/testdata/baselines/reference/compiler/objectBindingPatternDefaultMissingElements.symbols Records inferred symbols.
tsc/testdata/baselines/reference/compiler/objectBindingPatternDefaultMissingElements.errors.txt Records diagnostics.
tsc/testdata/baselines/reference/compiler/inferredRestTypeFixedOnce.errors.txt Updates implicit-any diagnostics.

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +16921 to +16923
name := c.getPropertyNameFromBindingElement(e)
if name != ast.InternalSymbolNameMissing && c.getPropertyOfType(t, name) == nil {
missingElements = append(missingElements, e)
Object binding padding now considers every missing binding element, but
a rest binding does not name a source property.

Treating it as a property synthesized an optional member with the rest
variable name. That made the rest variable contain itself and produced a
spurious implicit-any diagnostic.

Skip rest elements before looking up missing properties, matching object
binding-pattern inference. Add coverage for the inferred parameter and
rest-variable types and for the remaining required binding diagnostic.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Not started

Development

Successfully merging this pull request may close these issues.

function object parameter destructure field without default value will be ignored

2 participants