Open
Description
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.