Optional catch clause variables
Thanks to work done by @tinganho, TypeScript 2.5 implements a new ECMAScript feature that allows users to omit the variable in catch
clauses.For example, when using JSON.parse
you may need to wrap calls to the function with a try
/catch
, but you may not end up using the SyntaxError
that gets thrown when input is erroneous.
let input = "...";
try {
JSON.parse(input);
}
catch {
// ^ Notice that our `catch` clause doesn't declare a variable.
console.log("Invalid JSON given\n\n" + input)
}