Skip to content

Fix false implicit-any errors in annotated nested bindings - #64440

Draft
Ryan Cavanaugh (RyanCavanaugh) with Copilot wants to merge 9 commits into
mainfrom
copilot/fix-ts7031-nested-object-binding
Draft

Ryan Cavanaugh (RyanCavanaugh) with Copilot wants to merge 9 commits into
mainfrom
copilot/fix-ts7031-nested-object-binding

Conversation

Copilot AI commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Nested object bindings with = {} incorrectly reported TS7031 despite an enclosing parameter annotation supplying the binding element type.

function f({ inner: { b } = {} }: Outer) {
    return b; // number | undefined, not any
}
  • Cause

    • Object-literal padding reported implicit-any for every missing binding element, including elements rooted in annotated declarations.
  • Change

    • Report implicit-any during padding only when the root declaration lacks a type annotation.
    • Add regression coverage for nested bindings with and without sibling defaults.

Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix TS7031 false positive for nested object binding pattern Fix false implicit-any errors in annotated nested bindings Sep 24, 2026
@RyanCavanaugh

Copy link
Copy Markdown
Member

Copilot mcfly this and also explain why this is a correct fix

Copilot AI and others added 6 commits September 25, 2026 15:51
This reverts commit 2970fae.

Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com>
Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com>
Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com>
Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com>
Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com>
Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com>
@trevorade

Copy link
Copy Markdown
Contributor

I had my agent check this fix. Here's what it has to say about it.


Tried this against the cases we hit in our codebase. It clears all of them, and it also gets the types right in a nested callback case (deepCb(({inner: {b} = {}}) => b) gives b: string | undefined, same as 6.0).

Two cases still differ from 6.0.3:

// 1. Contextual type is `any`: TS7031 on `a` (6.0.3: clean)
declare function anyCb(cb: (x: any) => void): void;
anyCb(({a} = {}) => { void a; });

// 2. One element missing from the contextual type: TS7031 on `q` too (6.0.3: only TS2339 on `extra`)
interface Opts { q?: string; }
declare function onTab(cb: (id: string, opts?: Opts) => void): void;
onTab((id, {q, extra} = {}) => { void [id, q, extra]; });

(2) happens because hasContextualTypeForObjectBindingPattern is all-or-nothing, so one element without a contextual property type re-pads the whole pattern.

Also, the .types/.symbols baselines are missing the contextual(...) line from the test file, so TestLocal/objectBindingPatternDefaultAnnotated.ts fails as-is. No other baselines change.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

For Uncommitted Bug PR for untriaged, rejected, closed or missing bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TS7031 false positive for nested object binding pattern with = {} default in an annotated parameter (regression from #64043)

3 participants