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
{{ message }}
Repository navigation
Suggestion: CFA, assignment, strict null checks and function scope #17449
// @strictNullChecks: trueletfoo: {foo: string;}|undefined;foo={foo: 'bar'};document.addEventListener('click',()=>{foo.foo;// Object is possibly 'undefined'});foo.foo;
Currently, TypeScript resets the type of variables within a function scope, giving the error that the variable is possibly undefined, but it can be statically determined that after the function, the outer scope does no re-assignment. So it is possible to determine that there is no re-assignment and therefore foo will always be assigned.
Related to #9998 (trade-offs in CFA)
Related to #11498 (annotate immediately invoked callbacks)
As Daniel Rosenwasser (@DanielRosenwasser) noted, i do not think we can do the full analysis, where a function body is inlined at the call site for control flow analysis purposes.. #11498 might be a more viable path here.
Activity
DanielRosenwasser commentedon Jul 28, 2017
We could do wider analysis, but I don't know how computationally expensive that would get.
I personally do think that a solution in the same vein of #11498 would be more ideal, but we haven't explored that very deeply.
mhegazy commentedon Nov 20, 2017
As Daniel Rosenwasser (@DanielRosenwasser) noted, i do not think we can do the full analysis, where a function body is inlined at the call site for control flow analysis purposes.. #11498 might be a more viable path here.