Skip to content

TS7031 false positive: destructured parameter with default in a contextually typed arrow #1019

Open

Description

@asmither

Summary

tsrs reports TS7031 for a binding element in a destructured parameter with a default when the arrow function is contextually typed. The parameter's contextual type is optional (opts?: {...}). tsc 7.0.2 and bun check accept the same program.

This may be related to #664, which was closed as unable to reproduce. The pattern here is different: there is no type annotation on the parameter, and the type comes only from context.

Versions

  • tsrs: Version 7.1.0-beta (tsrs 0.25.0-ts7.1.0-beta, microsoft/TypeScript@3e9236361fa9), Linux x86_64
  • Reference: native tsc from typescript 7.0.2 exits 0, and bun check (Bun 1.4.4) exits 0.

Reproduction

tsconfig.json:

{ "compilerOptions": { "strict": true, "noEmit": true, "target": "es2022", "module": "esnext", "moduleResolution": "bundler" }, "files": ["repro.ts"] }

repro.ts:

type Props = { header?: (opts?: { actions?: string }) => string };
declare function render(props: Props): void;

render({ header: ({ actions } = {}) => actions ?? "" });
$ tsc -p .
$ echo $?
0
$ tsrs -p .
repro.ts(4,21): error TS7031: Binding element 'actions' implicitly has an 'any' type.
$ echo $?
2

Expected

No error. actions should be contextually typed as string | undefined from Props["header"].

We hit this in a real codebase, in a JSX prop (header={({ actions } = {}) => ...}). It was the only difference from tsc across about 5,000 files.

Activity

  1. oxc-captain commented on Nov 17, 2026

    @oxc-captain
    Contributor
    • Reproduced: No
    • Exploration: No
    • Unit Test: No — issue not reproduced; the pinned reference compiler agrees with tsrs
    • Priority: Priority P3: Narrow or low-impact issue. The reported diagnostic matches the pinned TypeScript Go compiler exactly, so this is a difference between JavaScript tsc 7.0.2 and TypeScript 7.1.0-beta rather than a tsrs defect.

    tsrs emits the same TS7031 diagnostic and exit code as the pinned TypeScript Go reference compiler (commit 3e9236361fa9, Version 7.1.0-beta) on the exact reproduction from the issue. The installed JavaScript tsc 7.0.2 accepts the program, but this repository uses the pinned Go compiler as the source of truth.

    I wasn't able to find a fix, but I identified some areas that may be relevant. The TS7031 diagnostic is emitted consistently by both tsrs and the pinned Go compiler, so the behavior appears intentional in Version 7.1.0-beta. No tsrs source change is necessary; any change in behavior would need to come from the upstream TypeScript Go reference implementation. The relevant logic would be in the checker paths that handle destructuring patterns and contextual typing for arrow-function parameters (e.g. crates/tsrs_checker in tsrs, corresponding code in the reference compiler).

    Full Triage Report

    Triage report for #1019

    Issue claim

    TS7031 false positive: destructured parameter with default in a contextually typed arrow.

    Input:

    type Props = { header?: (opts?: { actions?: string }) => string };
    declare function render(props: Props): void;
    
    render({ header: ({ actions } = {}) => actions ?? "" });

    Reporter says native tsc 7.0.2 and Bun check accept the program, while tsrs emits:

    repro.ts(4,21): error TS7031: Binding element 'actions' implicitly has an 'any' type.
    exit: 2
    

    Reproduction

    Created triage/gh-1019/tsconfig.json:

    { "compilerOptions": { "strict": true, "noEmit": true, "target": "es2022", "module": "esnext", "moduleResolution": "bundler" }, "files":["repro.ts"] }

    Created triage/gh-1019/repro.ts matching the issue exactly.

    Built tsrs from the checkout:

    cargo build --profile dev --locked -p tsrs_cli -p tsrs_testrunner
    

    Built the pinned TypeScript Go compiler from Cargo.toml:

    commit = 3e9236361fa97a9e6c685f4833ac457ae2d8c50a
    

    Sparse checkout under triage/gh-1019/ts-ref, built tsc_bin.

    Results

    tsrs

    $ ../../target/debug/tsrs -p . --pretty false
    repro.ts(4,21): error TS7031: Binding element 'actions' implicitly has an 'any' type.
    exit: 2
    

    Pinned Go tsc (3e9236361fa9, Version 7.1.0-beta)

    $ ./ts-ref/tsc_bin -p . --pretty false
    repro.ts(4,21): error TS7031: Binding element 'actions' implicitly has an 'any' type.
    exit: 2
    

    Installed JS tsc (7.0.2, for information only)

    $ tsc -p . --pretty false
    exit: 0
    

    Conclusion

    NOT REPRODUCED as a tsrs parity defect.

    The checked-out tsrs (built from this branch) produces the same diagnostic and exit status as the pinned TypeScript Go compiler. The difference is between TypeScript 7.0.2 (JavaScript) and 7.1.0-beta (the pinned Go reference implementation), not between tsrs and the pinned reference.

    Per this repository's triage rules, the pinned Go compiler is the specification. Since tsrs matches it, tsrs is correct here.

    This report was made by an LLM. The analysis may be wrong, and the potential fix might not work, but is intended as a starting point for exploring the issue.

  2. marklawlor-payble commented on Nov 17, 2026

    @marklawlor-payble

    The triage is right: this isn't a tsrs defect. It's an upstream TypeScript 7.1 regression, and tsrs is matching it.

    Published npm builds behave the same way on a minimal case:

    export const annotated: (args?: { path?: string }) => string = ({ path } = {}) => path ?? "";
    • typescript@7.0.2: no errors
    • typescript@7.1.0-beta: TS7031 on path
    • typescript@7.1.0-dev.20261117.1: TS7031 on path

    Upstream it bisects to microsoft/TypeScript#64043 and is tracked in microsoft/TypeScript#64974 and microsoft/TypeScript#64431. That probably means this issue can be closed in favour of those.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    triage: unable to reproduceAutomated investigation could not reproduce the report

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions