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
Support preserving type narrowing inside closures in some simple casesΒ #55528
I understand that types are not kept narrowed inside callbacks because the narrowing could in general not hold anymore in there, however there are some "simple" scenarios where we can be sure that the narrowing holds, for example:
This scenario is a sort of a simple edge case of the general problem because:
The maybe variable holds a primitive value, so it will be passed to other functions by copy, so those functions outside the closure can't change its value inside the closure.
The code executed before the console.log call is done forever, since it doesn't have any callbacks that assign to maybe, and it's not wrapped in an unterminated loop.
The "code" after the console.log call also has no assignments to "maybe", in fact it has no references to "maybe" at all.
Under these conditions it's impossible for narrowing the type inside our function in the example above to be wrong, so it should be preserved.
changed the title [-]Support narrowing type inside closure in some simple cases[/-][+]Support preserving type narrowing inside closures in some simple cases[/+]on Aug 27, 2023
Possibly, in some of those 450 comments π That sounds like a general umbrella issue though, maybe we need a smaller issue for this one "easily" addressable part of the problem.
Activity
[-]Support narrowing type inside closure in some simple cases[/-][+]Support preserving type narrowing inside closures in some simple cases[/+]MartinJohns commentedon Aug 27, 2023
I'm fairly sure this was discussed as part of #9998 already.
fabiospampinato commentedon Aug 27, 2023
Possibly, in some of those 450 comments π That sounds like a general umbrella issue though, maybe we need a smaller issue for this one "easily" addressable part of the problem.
typescript-bot commentedon Aug 31, 2023
This issue has been marked as "Duplicate" and has seen no recent activity. It has been automatically closed for house-keeping purposes.