QuizNot attempted
unknown vs any
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
unknownis the type-safe top type: anything is assignable TO it, but it is only assignable tounknown/anyand 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
unknownis expected and compare it.