Skip to content

Using variable defined by array destructuring assignment in default value of variables defined afterwards. #49989

@farazsa88

Description

@farazsa88

Bug Report

🔎 Search Terms

Array destructuring assignment default value 7022

🕗 Version & Regression Information

Exists in 3.3.3 - 4.8.0-beta

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about this behaviour

⏯ Playground Link

Playground link with relevant code

💻 Code

const [a, b = a + 1] = [2];
console.log(`a: ${a}, b: ${b}`);

🙁 Actual behavior

Types of a and b inferred as any, or if noImplicitAny enabled, shows error: 'a' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.(7022)

🙂 Expected behavior

Types of both a and b should be inferred as number.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptFix AvailableA PR has been opened for this issueHelp WantedYou can do this

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions