Bug Report
🔎 Search Terms
try block
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about try-catch blocks
⏯ Playground Link
Playground link with relevant code
💻 Code
function f(request: {params: {[param: string]: unknown;}}) {
let x = request.params.x;
try {
x = validate(x);
} catch (e) {}
try {
takesString(x); // Fails to compile, x is of type unknown.
} catch (e) {}
}
function validate(x: unknown): string { return ""; }
function takesString(s: string) {}
🙁 Actual behavior
In this example, the code fails to compile because tsc has deduced x in the second block to be of type unknown
🙂 Expected behavior
Since we have successfully exited the first try-catch block, x's type should be narrowed to string in the second.
Bug Report
🔎 Search Terms
try block
🕗 Version & Regression Information
⏯ Playground Link
Playground link with relevant code
💻 Code
🙁 Actual behavior
In this example, the code fails to compile because
tschas deducedxin the second block to be of typeunknown🙂 Expected behavior
Since we have successfully exited the first try-catch block,
x's type should be narrowed tostringin the second.