TypeScript interview questions
// 38 QUESTIONS · UPDATED MAY 2026
TypeScript interview questions for QA engineers. Type fundamentals, generics, utility types, narrowing, conditional types, and the patterns you encounter writing type-safe test code in Cypress, Playwright, and shared test libraries.
Showing 38 of 38 questions
- What is the difference between interface and type alias?Mid
Both define object shapes, but they differ in key ways: interfaces support declaration merging and are preferred for public contracts cla…
- Explain TypeScript generics with a Page Object example.Mid
Generics let you write a function or class that works with any type while keeping full type safety — the caller provides the concrete typ…
- What is TypeScript, and what advantages does it offer over plain JavaScript for test automation?Junior
TypeScript is a statically typed superset of JavaScript that compiles to plain JS. For test automation it provides compile-time error det…
- What are the primitive types in TypeScript, and what is the difference between `number`, `Number`, and `Number` the wrapper object?Junior
TypeScript's primitives are `string`, `number`, `boolean`, `bigint`, `symbol`, `null`, and `undefined`. Lowercase `number` is the primiti…
- What is the difference between `any`, `unknown`, and `never` in TypeScript?Junior
`any` disables all type checking — unsafe escape hatch. `unknown` is the type-safe alternative: you must narrow it before operating on it…
- How does TypeScript's type inference work, and when should you add explicit type annotations?Junior
TypeScript infers types from initializer values, return expressions, and contextual positions. Explicit annotations are needed for functi…
- How do optional and default parameters work in TypeScript?Junior
Optional parameters use `?` after the name and add `undefined` to their type. Default parameters use `= value` and are implicitly optiona…
- What are tuples in TypeScript, and when would you use them over an array or object?Junior
A tuple is a fixed-length array where each position has a specific type: `[string, number]`. Use tuples for function return values where…
- When should you use a TypeScript enum versus a string literal union type?Junior
String literal union types (`'pending' | 'active' | 'done'`) are preferred for most cases — they are lightweight, tree-shakeable, and pro…
- How does the `readonly` modifier work in TypeScript, and what are its limitations?Junior
`readonly` prevents reassignment of a property after initialization at compile time. It does not deep-freeze nested objects — a `readonly…
- How does TypeScript handle `null` and `undefined`, and what does `strictNullChecks` do?Junior
With `strictNullChecks: true`, `null` and `undefined` are not assignable to other types — they must be explicitly included in a union (`s…
- What is type narrowing in TypeScript, and what narrowing techniques are available?Mid
Type narrowing is TypeScript's ability to refine a broad type to a more specific one inside a conditional block. Techniques include: `typ…
- What are TypeScript's built-in utility types, and which are most useful in test automation?Mid
`Partial<T>` makes all properties optional. `Required<T>` makes all required. `Pick<T, K>` and `Omit<T, K>` select/exclude properties. `R…
- What does the `keyof` operator do in TypeScript?Mid
`keyof T` produces a union type of all the string (and symbol) keys of type `T`. Combining `keyof` with `T[K]` (indexed access) lets you…
- What are mapped types in TypeScript, and how do they work?Mid
Mapped types iterate over the keys of a type and transform each property. The syntax `{ [K in keyof T]: NewType }` produces a new type wi…
- What is the difference between `as` type assertion and the `satisfies` operator?Mid
`as SomeType` overrides TypeScript's inferred type and suppresses errors — it is a promise to the compiler you may not keep. `satisfies`…
- How do you correctly type async functions and Promise values in TypeScript?Mid
An `async` function's return type is `Promise<T>`. Use `Awaited<T>` (TypeScript 4.5+) to unwrap the resolved type of a Promise genericall…
- What is module augmentation in TypeScript, and when do you use it in a test project?Mid
Module augmentation extends the types of an existing module without modifying its source. Use it in test projects to add types to Playwri…
- What is a discriminated union in TypeScript, and why is it useful for modelling API responses?Mid
A discriminated union is a union type where every member has a shared literal property (`kind`, `type`, `status`) that uniquely identifie…
- What are conditional types in TypeScript, and what is the `infer` keyword?Mid
Conditional types use `T extends U ? X : Y` to produce a different type based on a condition. The `infer` keyword, used inside the extend…
- What is the difference between `extends` in class inheritance versus `extends` in a generic constraint?Mid
`class Dog extends Animal` is runtime inheritance — `Dog` inherits Animal's methods and prototype. `function fn<T extends Serializable>`…
- What does `strict: true` enable in `tsconfig.json`, and which flags matter most for test projects?Mid
`strict: true` enables a group of strict type-checking flags: `strictNullChecks`, `strictFunctionTypes`, `strictPropertyInitialization`,…
- How does TypeScript handle thrown errors in async functions, and why can't you type what a function throws?Mid
TypeScript does not track thrown types — the `throws` clause does not exist in TypeScript. An async function that throws returns a `Promi…
- What are the most important `tsconfig.json` settings for a Playwright test project?Mid
`target` and `module` set output JS version and module format. `strict: true` enables null and implicit-any safety. `moduleResolution: 'b…
- How do you type environment variables safely in a TypeScript test project?Mid
Access `process.env.VAR_NAME` and validate at startup — never trust individual accesses to return a defined string. Create a typed config…
- How do you add type definitions for a custom Cypress command in TypeScript?Mid
Implement the command in a `commands.ts` file, then extend the `Cypress.Chainable` interface in a `.d.ts` declaration file (or in the sam…
- How do you implement a type-safe builder pattern for test fixtures in TypeScript?Senior
A type-safe builder uses method chaining where each setter returns `this` (or a new builder instance), and a final `build()` method retur…
- What are template literal types in TypeScript, and what can they express?Senior
Template literal types combine string literal types using backtick syntax: `` `get${Capitalize<string & K>}` ``. They enable typed event…
- What is type variance in TypeScript, and why does it matter for function types?Senior
Variance describes how subtype relationships propagate through generic types. Covariant types (`T` in output positions) preserve subtype…
- What is structural typing in TypeScript, and how do you simulate nominal typing when needed?Senior
TypeScript uses structural typing — two types are compatible if they have the same shape, regardless of name. Nominal typing (identity by…
- How do you design a type-safe Page Object class hierarchy in TypeScript with Playwright?Senior
Use an abstract `BasePage` with a constructor accepting `Page` from Playwright. Each page class extends `BasePage`, declares its locators…
- What are advanced uses of the `infer` keyword in TypeScript conditional types?Senior
`infer` captures a type at a matched position inside a `extends` clause. Advanced uses: extracting tuple element types, unwrapping nested…
- How do branded types work in TypeScript, and when should you use them in a test project?Senior
Branded types add a phantom property to a primitive type, making structurally identical primitives incompatible without losing their unde…
- How would you design a typed plugin or extension system in TypeScript for a test framework?Senior
Use a generic registry type with a constraint that plugins must implement a declared interface. Declaration merging via module augmentati…
- What is your strategy for migrating a large JavaScript Playwright test suite to TypeScript?Senior
Enable `allowJs` + `checkJs` first to get compile errors without renaming files. Prioritize shared code (Page Objects, fixtures, helpers)…
- What techniques do you use to prevent `any` from spreading through a TypeScript codebase?Senior
`any` is contagious — it propagates through assignments and function returns. Prevent it with: `noImplicitAny` + `strict`, ESLint `@types…
- How do you standardize TypeScript usage across a large QA automation team?Lead
Establish a shared `tsconfig` base, enforced ESLint rules, a typed utility library, code review guidelines for type safety, and team trai…
- How do you make the business case for adopting TypeScript in a QA automation project?Lead
Frame the ROI in terms the business cares about: faster onboarding, fewer flaky tests from type mismatches, safer refactoring when the pr…