Description
openedon Jul 2, 2024
π Search Terms
useUnknownInCatchVariables
π Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about useUnknownInCatchVariables
β― Playground Link
No response
π» Code
No response
π Actual behavior
With useUnknownInCatchVariables
:unknonw
is magically injected after err (in catch (err)
)
try {
console.log("in try")
}
catch (err) {
console.log("in catch")
console.log(err.message)
}
This results in a mysterious failure like so (from deno i.e. swc):
error: TS18046 [ERROR]: 'err' is of type 'unknown'.
console.log(err.message)
The design of this option is very wrong, it's not worth the tiny saving of not having to type :unknown
give how mysterious the above error is for a user who isn't aware of this option. It should have been designed to require this declaration rather than injecting it.
I realize this option can't be fixed at this point and it's probably not worth introducing a similar one with the better behavior. Perhaps as an alternative swc (and maybe other compilers) could be fixed to give an error that at least mentions useUnknownInCatchVariables.
π Expected behavior
Something less mysterious :)
Additional information about the issue
None