Reputation: 109
Yesterday, whilst working on the codebase, we had no issues whatsoever.
This morning, on the other hand, we have walked into every error being treated as Unknown
vs the previous any
type.
How can I revert this change. I can only find a pile of terribly confusing github convos which allude to the change, but none which actually specify in which version this breaking change was added.
TIA.
Upvotes: 6
Views: 6163
Reputation: 275927
none which actually specify in which version this breaking change was added
This is a new feature of TypeScript 4.4. Catch parameters now default to unknown
. This makes the error handling safer. As you have found "useUnknownInCatchVariables": false
is one workaround.
However I recommend not setting this option to allow safety for future code, and instead adding explicit any
if that makes sense or adding custom type guards to take benefit from the safety in existing code.
Upvotes: 7
Reputation: 109
After a ton of googling, I found this in a playground comment...
"useUnknownInCatchVariables": false,
in your compiler options will fix it.
Upvotes: 4