TypeScript
The type system from narrowing to conditional and mapped types, plus typing React.
1.What is the difference between `any`, `unknown` and `never` in TypeScript?
The escape hatch, the safe top type, and the empty bottom type.
2.What is the difference between an interface and a type alias in TypeScript?
Declaration merging and extends vs unions, tuples and type-level computation.
3.What is structural typing in TypeScript and what are its implications?
Compatibility by shape, excess property checks, and when you need nominal types.
4.What is the difference between a type assertion and a type annotation in TypeScript?
Checking vs overriding the compiler, non-null assertions, and safer alternatives.
5.How do you type event handlers in React with TypeScript?
Synthetic event types, handler aliases, target vs currentTarget, and DOM listener types.
6.How do you type React component props in TypeScript?
Props types, ReactNode children, native element props, exclusive variants and React.FC.
7.Which built-in TypeScript utility types do you use most, and how do they work?
Partial, Pick, Omit, Record, ReturnType, Awaited and friends, plus their pitfalls.
8.What are discriminated unions in TypeScript and how do you enforce exhaustive handling?
Tagged unions that make impossible states unrepresentable, checked with never.
9.Explain generics and generic constraints in TypeScript
Type parameters that preserve relationships, constraints, defaults, const and NoInfer.
10.Explain `keyof`, `typeof` and indexed access types in TypeScript
Deriving key unions, value types and property types from existing code.
11.What does the `satisfies` operator do in TypeScript and how is it different from a type annotation or `as`?
Validate against a type while keeping precise inference.
12.What does `strict` mode enable in TypeScript, and which extra flags are worth turning on?
The strict family, noUncheckedIndexedAccess, exactOptionalPropertyTypes and migration strategy.
13.How does type narrowing work in TypeScript, and how do you write type guards?
Control-flow narrowing, user-defined and inferred type predicates, and assertion functions.
14.Do TypeScript types exist at runtime? How do you validate external data?
Type erasure, trust boundaries, schema validation and type stripping.
15.What are conditional types and the `infer` keyword in TypeScript?
Type-level branching, pattern matching with infer, and distribution over unions.
16.What does `as const` do in TypeScript?
Const assertions for literal, readonly types and deriving unions from values.
17.What are assertion functions in TypeScript?
Functions that narrow by throwing: asserts condition and asserts value is T.
18.What are branded (nominal) types in TypeScript and why use them?
Phantom brands that stop same-shape values being mixed up and mark validated data.
19.How do access modifiers work in TypeScript classes, and how is `private` different from `#private`?
Compile-time vs runtime privacy, parameter properties, abstract and override.
20.What are `.d.ts` declaration files and when do you write them?
Types-only files for JS code, assets and globals, and how packages ship types.
21.What is declaration merging in TypeScript?
How interfaces, namespaces and enums merge, and how that powers global and module augmentation.
22.Should you use enums or union literal types in TypeScript?
Runtime enums vs erasable unions, as const objects, and modern toolchain constraints.
23.What are excess property checks in TypeScript and when do they apply?
Why fresh object literals reject unknown keys, and when the check doesn't fire.
24.What are function overloads in TypeScript and when should you use them?
Multiple call signatures with one hidden implementation, and the alternatives.
25.What are index signatures in TypeScript and what are their pitfalls?
Dictionaries vs exhaustive Records, noUncheckedIndexedAccess, and when to use Map.
26.What are mapped types in TypeScript and how does key remapping work?
Iterating keys to build types, modifiers, and as-based renaming and filtering.
27.What is module augmentation in TypeScript and when would you use it?
Extending library and global types with declare module and declare global.
28.How do you model immutability in TypeScript with `readonly`?
readonly modifiers, Readonly, readonly arrays and as const, and their limits.
29.What are tuple types in TypeScript, including variadic and labeled tuples?
Fixed-position arrays, optional, rest and labeled elements, and variadic tuple types.
30.What are type-only imports in TypeScript and what does `verbatimModuleSyntax` do?
Why per-file transpilers need explicit type imports, and the modern tsconfig setup.
31.How do you type refs in React with TypeScript, and what changed in React 19?
DOM refs, mutable refs, ref as a prop, imperative handles and callback ref cleanups.
32.How do you type `useReducer` state and actions in TypeScript?
Discriminated-union actions, exhaustive reducers and typed dispatch.
33.What are distributive conditional types in TypeScript?
How conditional types map over unions, how to disable it, and the never trap.
34.How do you write generic React components in TypeScript?
Type parameters that connect props, tsx syntax quirks, and wrappers that lose generics.
35.What are template literal types in TypeScript and what are they useful for?
Building and parsing string literal types for handlers, routes and typed paths.
36.Explain covariance, contravariance and invariance in TypeScript
How generic and function types relate under subtyping, strictFunctionTypes and in/out annotations.
37.What are `const` type parameters in TypeScript 5.0?
as const-style literal inference without caller ceremony.
38.What are `using` declarations (explicit resource management) in TypeScript?
Scope-bound cleanup with Symbol.dispose, await using and DisposableStack.