Skip to content

Undetected access to uninitialized variable #42678

Closed
@tuedeldude

Description

@tuedeldude

🔎 Search Terms

  • ReferenceError: can't access lexical declaration before initialization
  • undetected access uninitialized variable
  • used before assignment

🕗 Version & Regression Information

Reproducible in Playground with versions > 3.3.3333 including

  • 4.1.3
  • 4.2.0-dev20210206
  • ...

Not reproducible with 3.3.3333

This changed between versions 3.3.3333 and 3.5.1

⏯ Playground Link

Playground link with relevant code

💻 Code

const [
    a,
    b,
] = ((): [number, number] => {
    // Undetected access to uninitialized variable
    console.log(a);
    return [
        0,
        0,
    ];
})();

🙁 Actual behavior

Undetected access of uninitialized variable. Crash at JavaScript runtime.

🙂 Expected behavior

Compile time error: "Variable 'a' is used before being asigned."

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScript

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions