Back to questions
JuniorTheoryCommon
What does tsc report for this file?
try {
JSON.parse("{");
} catch (e) {
console.log(e.message);
}An error: e has the type unknown
- Expecting
eto be anErrorincatch:throwaccepts any value, so under strict mode tsc typeseasunknown. - Expecting tsc to check the text inside
JSON.parse("{"): it sees only astring, and the bad JSON fails at run time.
- How do you read
e.messagesafely in thiscatch? - Why is
etypedanyin a promise's.catch((e) => …)butunknownin atry/catch?