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
Seems like a duplicate of #11498.
Currently TypeScript never considers when a function is called when checking it. So it assumes any variables it closes over will have been defined by the time the function is called.
If this was instead a suggestion to copy the runtime behavior and throw ReferenceError instead of getting undefined when transpiling to es5, that's probably too expensive to do for every variable that happens to be used in a closure -- and we currently have no way of detecting that a function is called only when its closed-over variables have already been defined, so we would have to do that for every variable.
Note that if you don't need to support old browsers you can set --target es6 which would solve the issue for you.
Uh oh!
There was an error while loading. Please reload this page.
TypeScript Version: 3.0.1
Search Terms: variable scope es2015 label:Bug
Code
Expected behavior:
In V8 (nodejs, chrome) and SpiderMonkey (firefox),
it can't compileit runs with ReferenceError if foo is not initialized.Actual behavior:
It compiles and runs, showing
foo: undefined
andfoo: 42
.Playground Link: playground
Related Issues: #19503 looks similar, I guess.
The text was updated successfully, but these errors were encountered: