Need Assistance?

support@tutorialshub.in

Core Types & Special Types

any vs unknown (Why unknown is Safer)

ADVERTISEMENT
TypeScript Free Lesson
5 min read
ADVERTISEMENT

Using any completely turns off TypeScript's type checker—you can call methods on it that don't exist and crash at runtime. When you genuinely don't know a value's type yet (like JSON from an external API), use unknown instead.

unknown forces you to check what the value actually is (with typeof or a validator) before using it.

ADVERTISEMENT
Hi, I'm Tuby! Here to help you