Closed
Description
TypeScript Version: 4.0.0-dev.20200612
Search Terms: nested try
Code
type State
= {tag: "one"}
| {tag: "two"}
| {tag: "three"}
function notallowed(arg: number) {
let state: State = {tag: "one"};
try {
state = {tag: "two"};
try { // <- this inner try causes a problem
state = {tag: "three"}; // <- this should make "three" be a possibility but when inside a try, typescript "forgets" it.
}
finally {}
}
catch (err) {
state.tag; // <- this should be "one" | "two" | "three" but typescript says it is "one" | "two"
if (state.tag !== "one" && state.tag !== "two") {
console.log(state.tag); // <- typescript reports a type error here
}
}
}
Expected behavior:
The example code should compile without error.
Actual behavior:
The compiler reports a type error as though the code in the inner try can't happen
Playground Link:
Related Issues: