6

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.

2
  • Can you elaborate your problem further, maybe with a code example? What is broken now and which error message to you get at the moment, did you update dependencies? Commented Sep 7, 2021 at 9:44
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. Commented Sep 11, 2021 at 10:15

2 Answers 2

7

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.

More

Sign up to request clarification or add additional context in comments.

Comments

4

After a ton of googling, I found this in a playground comment...

"useUnknownInCatchVariables": false, in your compiler options will fix it.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.