Interview Q&A · questions with model answers

TypeScript Developer Interview Questions

Part of the study plan for: Frontend Engineer · Full Stack Engineer

Ordered by how often they're asked. Most-asked answers are free to read in full; members see every answer and can rate their confidence on each.

  1. How do you type React component props, children and events in TypeScript?

    Declare a props type or interface and annotate the function parameter; type children as React.ReactNode; use event types like React.ChangeEvent<HTMLInputElement> and…

  2. How do you type hooks like `useState`, `useReducer`, `useRef` and context?

    useState infers from the initial value; pass a generic when the initial value is narrower than the eventual type (useState<User | null>(null)). Type useReducer with a discriminated union of actions.…

  3. How do you write a generic React component (e.g., a typed List or Select)?

    Declare the component as a generic function, function List<T>({ items, renderItem }: ListProps<T>); TypeScript infers T from the props at the call site, so callbacks receive correctly typed items.

  4. How would you migrate a large JavaScript codebase to TypeScript?

    Incrementally: add tsconfig with allowJs (and optionally checkJs with JSDoc types), rename files to .ts gradually starting from leaf modules, add types for shared models first, start with loose…

  5. How do you model immutability in TypeScript?

    Use readonly properties, Readonly<T>, ReadonlyArray<T>/readonly T[], as const, and ReadonlyMap/ReadonlySet. These prevent mutation at compile time, but don't freeze objects at runtime.

  6. How should you handle errors in `catch` blocks in TypeScript?

    With useUnknownInCatchVariables (part of strict), the caught value is unknown, so narrow it (if (err instanceof Error)) before using .message. For typed error handling, consider result types ({ ok:…

  7. How do you test types themselves?

    Write type-level assertions with tools like Vitest's expectTypeOf, tsd, or @ts-expect-error comments in test files, and run tsc in CI so regressions in complex generic types are caught.

  8. How do you type an Express/Node API in TypeScript?

    Use @types/express (or Express 5's types), type route handlers with Request<Params, ResBody, ReqBody, Query>, validate request bodies at runtime with Zod and infer the types, augment Request for…

  9. How can you share types between frontend and backend?

    Options: a shared package of DTO types/schemas in a monorepo, generating types from an OpenAPI schema (openapi-typescript), GraphQL codegen, or end-to-end typed RPC like tRPC, where the client…

  10. How would you implement a `DeepPartial<T>` type?

    Use a recursive mapped type that makes each property optional and recurses into objects, while leaving functions and primitives alone.

  11. How do you type async functions and promises?

    An async function's return type is Promise<T>. Use Awaited<T> to unwrap promise types, type Promise.all results via inference (tuples are preserved), and use PromiseSettledResult<T> for allSettled.

  12. How do you type environment variables safely?

    Validate process.env at startup with a schema (Zod, envalid, @t3-oss/env-*) and export a typed config object, rather than augmenting NodeJS.ProcessEnv and assuming values exist.

  13. How do you publish a TypeScript library with correct types for ESM and CommonJS consumers?

    Emit JavaScript plus .d.ts files, set package.json exports with types/import/require conditions (and .d.mts/.d.cts where needed), set type, and verify with tools like @arethetypeswrong/cli and…

  14. How would you type an event emitter so event names and payloads are checked?

    Define an event map type ({ login: { userId: string }; logout: void }) and make on/emit generic over K extends keyof Events, so the listener receives Events[K].

  15. How do you write a type-safe fetch wrapper?

    Make the wrapper generic over the response type but validate the JSON at runtime with a schema passed in, e.g. getJson<T>(url, schema: z.ZodType<T>): Promise<T>, and return a discriminated result or…

  16. How do you implement mixins in TypeScript?

    Write functions that take a base class constructor (TBase extends new (...args: any[]) => {}) and return a class extending it with added members; compose them like Timestamped(Activatable(User)).

  17. How do you add types to globals like `window`?

    In a module file, use declare global { interface Window { analytics: Analytics } } and include export {} so the file is a module; interface merging adds the property to the global Window type.

  18. How do you type Maps, Sets and WeakMaps?

    Use generics: new Map<string, User>(), new Set<number>(), new WeakMap<object, Metadata>(). map.get(key) returns V | undefined, so you must handle missing values.

  19. How would you type a generic repository class?

    Parameterize the class over the entity type and ID type (class Repository<T extends { id: Id }, Id = string>), with methods returning Promise<T | undefined>, and use Omit<T, 'id'> for create inputs.

  20. How do you safely use data from `JSON.parse` without a schema library?

    Treat the result as unknown and write type guards that check each required field's type, returning value is T, before using it.

  21. How do you make a class implement an interface, and what does `implements` actually check?

    class Foo implements Bar makes the compiler check that Foo's instance side satisfies Bar; it doesn't change the class's type or add members, and the class could satisfy the interface structurally…

Was this page helpful?

Report a mistake