80%
TypeScript Types, interfaces, generics, narrowing and utility types0/25 questions known
1. Why TypeScript?
DefinitionTypeScript = JavaScript + a static type system.
Catches typos, wrong arguments and null bugs before running.
Better editor autocomplete and safe refactors across a big codebase.
Types document APIs (props, responses, DB models).
Common mistakeTypes don't validate data at runtime.
2. Basic types, interface vs type
Objects and classes; can be extended with extends: Anything: unions, tuples, primitives, mapped types
Declaration merging (re-open to add fields): Cannot be re-opened
Good default for object shapes and public APIs: Needed for unions and computed types
any turns type checking off — avoid it.
unknown is the safe "anything": you must narrow it before use.
never = a value that can't exist (exhaustive checks, functions that throw).
3. Narrowing and discriminated unions
Narrow with typeof, instanceof, in, equality and truthiness checks.
A user-defined type guard: function isUser(x: unknown): x is User { … }.
4. Generics
DefinitionGenerics are type parameters: write one function or type that works for many types while keeping them linked.
5. Utility types
Partial<T>: every property optional (PATCH bodies)
Required<T>: every property required
Readonly<T>: every property readonly
Pick<T, "a" | "b">: only those keys
6. TypeScript with React
ReviseTypes are erased at runtime → validate external data.
Most asked (8)
QWhat is TypeScript and why use it over JavaScript?TypeScript is JavaScript plus a static type system.
QWhat is the difference between interface and type?For describing object shapes they are almost interchangeable.
QWhat is the difference between any, unknown and never?- any switches type checking off.
QWhat are generics? Give an example.Generics are type parameters: they let a function, class or type work with many types while keeping the relationship between input and…
QWhich built-in utility types do you use most?- Partial<T>: all properties optional (update payloads) - Required<T>: all properties required - Readonly<T>: all properties read-only -…
QWhat is type narrowing? What is a type guard?Narrowing is how TypeScript refines a broad type (like string | number) to a more specific one inside a branch, by following your runtime…
QWhat is a discriminated union, and how do you make a switch exhaustive?A discriminated union is a union of object types that all share a literal "tag" property, such as kind or status.
QWhat does strict mode do? Why does strictNullChecks matter so much?"strict": true in tsconfig.json turns on a family of checks, including noImplicitAny, strictNullChecks, strictFunctionTypes and…