What is the difference between any, unknown and never in TypeScript?
any turns off checking. unknown is a type-safe any: you must narrow it before use. never means a value cannot exist, used for exhaustive checks and functions that always throw.
Frontend 路 Intern to senior
TypeScript questions show whether you use the type system to catch bugs or only to silence the compiler with `any`. Interns are asked what TypeScript adds on top of JavaScript; mid-level and senior candidates are asked to model real data with generics, unions and narrowing.
7 of 10 questions match
Clear filtersany turns off checking. unknown is a type-safe any: you must narrow it before use. never means a value cannot exist, used for exhaustive checks and functions that always throw.
Generics are type parameters: they let a function, class or type work with many types while keeping the relationship between inputs and outputs, instead of falling back to any.
A union (A | B) is a value that is one of the members. An intersection (A & B) is a value that must satisfy both types at once.
Utility types are built-in helpers that transform an existing type: Partial makes every field optional, Required the opposite, Pick keeps a set of keys, Omit removes them, and Record builds a key/value map.
Narrowing is when TypeScript shrinks a wide type (such as a union) to a more specific type after a runtime check like typeof, instanceof, in, or a custom type guard.
A string union such as "admin" | "user" exists only in the type system and erases to plain strings. A TypeScript enum compiles to a JavaScript object (unless it is a const enum), which is extra runtime code and a weaker default.
TypeScript fills in types you omit: literals get their literal or widened type, function return types are inferred from return statements, and generic arguments are inferred from the values you pass.