You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
// https://github.com/microsoft/TypeScript/issues/5174functionf(x: number){switch(x){case1:
letx=1;case2:
x=2;// should be error because of TDZ}}// https://github.com/microsoft/TypeScript/issues/52924#issue-1595962667functionh(){letresult=g();letx: number=10;returnresult;functiong(){returnx;}}
🙁 Actual behavior
No error reported.
🙂 Expected behavior
TDZ check should be applied.
The text was updated successfully, but these errors were encountered:
TL;DR it's quite difficult to detect these with high enough precision to make it worthwhile.
TS does have TDZ checking for cases where it can easily be detected that a TDZ violation will always occur. for cases where a TDZ violation may or may not occur, it's more tricky since this is a sort of error that is not silenceable through the type system, so we don't want to issue it unless we can be very sure that a violation is definitely occurring. And it's easy to make programs which appear like they might have a TDZ violation, but don't by construction. and, after all, if your function body really does unconditionally raise a TDC error, then finding that out at build time vs at first execution has fairly low value compared to other checks we might be making.
For switch blocks, see this PR: #47160. This seems to be a pretty rare case it doesn't come up very often and it's actually pretty difficult to only issue correct errors in this case, so it didn't seem like a good use of finite time
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
⏯ Playground Link
Playground link with relevant code
💻 Code
🙁 Actual behavior
No error reported.
🙂 Expected behavior
TDZ check should be applied.
The text was updated successfully, but these errors were encountered: