TypeScript · Junior · Question 3 of 75

How does unknown differ from any?

Explanation

any turns typing off and "infects" everything it touches. unknown is the safe counterpart: the value can be anything, but you can use it only after a check (typeof x === 'string'). For data from JSON.parse and catch (e), unknown is the right choice.

Further reading

Problem with a question

TypeScript · Junior · question 3

Test yourself

Take the TypeScript · Junior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz