Bug Report
🔎 Search Terms
undefined object, callback, closure, hoisting, arrow function
🕗 Version & Regression Information
- This is the behavior in every version I tried (every version available in the playground, from 3.3.3 to Nightly 5.0.0), and I reviewed the FAQ for entries about
undefined, closure, hoisting
⏯ Playground Link
Playground link with relevant code
💻 Code
constfooMap:Map<string,Array<number>>=newMap()functionsomeFunction(arg:Array<number>){//...}constvalues=[1,2,3,4,5];letfoo=fooMap.get("a");if(foo==null){foo=[];}// The issue is this line, where TS says that `foo` may be undefinedvalues.forEach((v)=>foo.push(v));// In this line, TS recognizes that `foo` is not undefinedsomeFunction(foo);🙁 Actual behavior
A variable (in this case, foo) is being marked as possibly undefined when used inside of a closure, although it will never be null at that point.
🙂 Expected behavior
I expect foo to be not-null.
I apologize if the observed behaviour is expected -- but, if it is, can someone explain why?
Bug Report
🔎 Search Terms
undefined object, callback, closure, hoisting, arrow function
🕗 Version & Regression Information
undefined,closure,hoisting⏯ Playground Link
Playground link with relevant code
💻 Code
🙁 Actual behavior
A variable (in this case,
foo) is being marked as possibly undefined when used inside of a closure, although it will never be null at that point.🙂 Expected behavior
I expect
footo be not-null.I apologize if the observed behaviour is expected -- but, if it is, can someone explain why?