Assignments in the try-block are unconditionally assumed to have never happened in the catch-block #16682
Labels
Suggestion
An idea for TypeScript
Too Complex
An issue which adding support for may be too complex for the value it adds
TypeScript Version: 2.4.0
Code
The following is self-explanatory and nice. There is only one way an error can be thrown, therefore the compiler can make an assumption that
res
never got assigned in the try-block, if the catch-block is reached.If we start adding to this example however, strange things happen. In the example below, the compiler makes the same assumption, even though it seems incorrect.
res1
assignment succeeded and its value will be{ value: 42 }
in the catch-block.Expected behavior:
I'm not necessarily sure how this could be solved tbh. The only naive thing that comes to my mind is to only make this assumption about the last assignment in the try-block.
The text was updated successfully, but these errors were encountered: