Skip to content

Why TDZ checks are not implemented #54343

Closed
@yf-yang

Description

@yf-yang

Bug Report

It may not be a bug, because I see that you clearly know what TDZ check is (such as the code example in this issue), but it is not applied. I did find some related issues reported by TypeScript team members such as #5174 several years before, but it still passes the check now.

Just out of curiosity, would you please explain why such checks are not (fully) implemented?

🔎 Search Terms

TDZ check

🕗 Version & Regression Information

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

⏯ Playground Link

Playground link with relevant code

💻 Code

// https://github.com/microsoft/TypeScript/issues/5174
function f(x: number) {
    switch(x) {
        case 1:
            let x = 1;
        case 2:
            x = 2; // should be error because of TDZ
    }
}

// https://github.com/microsoft/TypeScript/issues/52924#issue-1595962667
function h() {
    let result = g();
    let x: number = 10;
    return result;

    function g() {
        return x;
    }
}

🙁 Actual behavior

No error reported.

🙂 Expected behavior

TDZ check should be applied.

Metadata

Metadata

Assignees

No one assigned

    Labels

    QuestionAn issue which isn't directly actionable in code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions