Skip to content

QuizNot attempted

unknown vs any

What can you do with a value of type unknown without narrowing it first?
1–4 to choose, Enter to submit
Show answer & explanation

Correct answer:

  • Only assign it to unknown/any, or compare it with ===; property access and calls are errors
  • unknown is the type-safe top type: anything is assignable TO it, but it is only assignable to unknown/any and supports equality checks
  • property access, calls and arithmetic are errors until you narrow (typeof, instanceof, in, a type guard).
  • Not 'anything, like any': that is any, which switches checking off and leaks.
  • Not 'call but not read': calling is also an error.
  • Not 'nothing at all': you can still pass it where unknown is expected and compare it.