Interview question bank

TypeScript Interview Questions and Answers

54 TypeScript interview questions, each with a short answer you can say in the interview, a detailed explanation, a real-world example and an interview tip; 25 of them are marked as frequently asked. Freshers can start with the first section; experienced testers can jump to the harder questions.

TypeScript interview questions for freshers

Beginner3 Years Frequently asked

1. What is type inference, and why does it matter in TypeScript?

Answer: type inference is a core TypeScript concept used to make testing decisions more accurate, repeatable, and aligned with product risk.

Detailed explanation, example and interview tip

A strong explanation of type inference should cover its purpose, the problem it solves, when it is appropriate, and where it can mislead a team. In TypeScript, use it deliberately rather than as a checklist item: connect it to observable behavior, choose clear pass/fail evidence, and record assumptions so another engineer can reproduce the result.

Real-world example

During release planning, the team used type inference to focus validation on the most important behavior and to communicate residual risk before deployment.

Interview tip

Answer in four parts: definition, suitable use case, limitation, and a concrete project example.

Beginner5 Years Frequently asked

2. What is generic constraints, and why does it matter in TypeScript?

Answer: generic constraints is a core TypeScript concept used to make testing decisions more accurate, repeatable, and aligned with product risk.

Detailed explanation, example and interview tip

A strong explanation of generic constraints should cover its purpose, the problem it solves, when it is appropriate, and where it can mislead a team. In TypeScript, use it deliberately rather than as a checklist item: connect it to observable behavior, choose clear pass/fail evidence, and record assumptions so another engineer can reproduce the result.

Real-world example

During release planning, the team used generic constraints to focus validation on the most important behavior and to communicate residual risk before deployment.

Interview tip

Answer in four parts: definition, suitable use case, limitation, and a concrete project example.

Beginner7 Years Frequently asked

3. What is conditional types, and why does it matter in TypeScript?

Answer: conditional types is a core TypeScript concept used to make testing decisions more accurate, repeatable, and aligned with product risk.

Detailed explanation, example and interview tip

A strong explanation of conditional types should cover its purpose, the problem it solves, when it is appropriate, and where it can mislead a team. In TypeScript, use it deliberately rather than as a checklist item: connect it to observable behavior, choose clear pass/fail evidence, and record assumptions so another engineer can reproduce the result.

Real-world example

During release planning, the team used conditional types to focus validation on the most important behavior and to communicate residual risk before deployment.

Interview tip

Answer in four parts: definition, suitable use case, limitation, and a concrete project example.

Beginner10+ Years Frequently asked

4. What is enums versus literal unions, and why does it matter in TypeScript?

Answer: enums versus literal unions is a core TypeScript concept used to make testing decisions more accurate, repeatable, and aligned with product risk.

Detailed explanation, example and interview tip

A strong explanation of enums versus literal unions should cover its purpose, the problem it solves, when it is appropriate, and where it can mislead a team. In TypeScript, use it deliberately rather than as a checklist item: connect it to observable behavior, choose clear pass/fail evidence, and record assumptions so another engineer can reproduce the result.

Real-world example

During release planning, the team used enums versus literal unions to focus validation on the most important behavior and to communicate residual risk before deployment.

Interview tip

Answer in four parts: definition, suitable use case, limitation, and a concrete project example.

Beginner3 Years

5. How would you apply union types in a production TypeScript project?

Answer: Apply union types through an explicit, repeatable design: define the expected behavior, automate the highest-risk path, capture useful diagnostics, and verify the result against a stable oracle.

Detailed explanation, example and interview tip

In a production TypeScript project, start by identifying the risk that union types controls and the evidence needed to prove the behavior. Keep setup, action, verification, and cleanup separate; parameterize environment-specific values; and make failures explain the business impact. Run the smallest relevant check on each change, broader coverage in the pipeline, and review flaky or slow results rather than hiding them with retries.

Real-world example

A team introduced a focused union types check at the layer closest to the risk, attached diagnostics to failures, and used the result as a release signal instead of relying on manual confirmation.

Interview tip

Describe one trade-off, one failure mode, and one measurable outcome when discussing union types.

Beginner3 Years

6. What is intersection types, and why does it matter in TypeScript?

Answer: intersection types is a core TypeScript concept used to make testing decisions more accurate, repeatable, and aligned with product risk.

Detailed explanation, example and interview tip

A strong explanation of intersection types should cover its purpose, the problem it solves, when it is appropriate, and where it can mislead a team. In TypeScript, use it deliberately rather than as a checklist item: connect it to observable behavior, choose clear pass/fail evidence, and record assumptions so another engineer can reproduce the result.

Real-world example

During release planning, the team used intersection types to focus validation on the most important behavior and to communicate residual risk before deployment.

Interview tip

Answer in four parts: definition, suitable use case, limitation, and a concrete project example.

Beginner3 Years

7. How would you apply generics in a production TypeScript project?

Answer: Apply generics through an explicit, repeatable design: define the expected behavior, automate the highest-risk path, capture useful diagnostics, and verify the result against a stable oracle.

Detailed explanation, example and interview tip

In a production TypeScript project, start by identifying the risk that generics controls and the evidence needed to prove the behavior. Keep setup, action, verification, and cleanup separate; parameterize environment-specific values; and make failures explain the business impact. Run the smallest relevant check on each change, broader coverage in the pipeline, and review flaky or slow results rather than hiding them with retries.

Real-world example

A team introduced a focused generics check at the layer closest to the risk, attached diagnostics to failures, and used the result as a release signal instead of relying on manual confirmation.

Interview tip

Describe one trade-off, one failure mode, and one measurable outcome when discussing generics.

Beginner5 Years

8. How would you apply keyof operator in a production TypeScript project?

Answer: Apply keyof operator through an explicit, repeatable design: define the expected behavior, automate the highest-risk path, capture useful diagnostics, and verify the result against a stable oracle.

Detailed explanation, example and interview tip

In a production TypeScript project, start by identifying the risk that keyof operator controls and the evidence needed to prove the behavior. Keep setup, action, verification, and cleanup separate; parameterize environment-specific values; and make failures explain the business impact. Run the smallest relevant check on each change, broader coverage in the pipeline, and review flaky or slow results rather than hiding them with retries.

Real-world example

A team introduced a focused keyof operator check at the layer closest to the risk, attached diagnostics to failures, and used the result as a release signal instead of relying on manual confirmation.

Interview tip

Describe one trade-off, one failure mode, and one measurable outcome when discussing keyof operator.

Beginner5 Years

9. What is typeof type queries, and why does it matter in TypeScript?

Answer: typeof type queries is a core TypeScript concept used to make testing decisions more accurate, repeatable, and aligned with product risk.

Detailed explanation, example and interview tip

A strong explanation of typeof type queries should cover its purpose, the problem it solves, when it is appropriate, and where it can mislead a team. In TypeScript, use it deliberately rather than as a checklist item: connect it to observable behavior, choose clear pass/fail evidence, and record assumptions so another engineer can reproduce the result.

Real-world example

During release planning, the team used typeof type queries to focus validation on the most important behavior and to communicate residual risk before deployment.

Interview tip

Answer in four parts: definition, suitable use case, limitation, and a concrete project example.

Beginner5 Years

10. How would you apply mapped types in a production TypeScript project?

Answer: Apply mapped types through an explicit, repeatable design: define the expected behavior, automate the highest-risk path, capture useful diagnostics, and verify the result against a stable oracle.

Detailed explanation, example and interview tip

In a production TypeScript project, start by identifying the risk that mapped types controls and the evidence needed to prove the behavior. Keep setup, action, verification, and cleanup separate; parameterize environment-specific values; and make failures explain the business impact. Run the smallest relevant check on each change, broader coverage in the pipeline, and review flaky or slow results rather than hiding them with retries.

Real-world example

A team introduced a focused mapped types check at the layer closest to the risk, attached diagnostics to failures, and used the result as a release signal instead of relying on manual confirmation.

Interview tip

Describe one trade-off, one failure mode, and one measurable outcome when discussing mapped types.

Beginner7 Years

11. How would you apply unknown versus any in a production TypeScript project?

Answer: Apply unknown versus any through an explicit, repeatable design: define the expected behavior, automate the highest-risk path, capture useful diagnostics, and verify the result against a stable oracle.

Detailed explanation, example and interview tip

In a production TypeScript project, start by identifying the risk that unknown versus any controls and the evidence needed to prove the behavior. Keep setup, action, verification, and cleanup separate; parameterize environment-specific values; and make failures explain the business impact. Run the smallest relevant check on each change, broader coverage in the pipeline, and review flaky or slow results rather than hiding them with retries.

Real-world example

A team introduced a focused unknown versus any check at the layer closest to the risk, attached diagnostics to failures, and used the result as a release signal instead of relying on manual confirmation.

Interview tip

Describe one trade-off, one failure mode, and one measurable outcome when discussing unknown versus any.

Beginner7 Years

12. What is never type, and why does it matter in TypeScript?

Answer: never type is a core TypeScript concept used to make testing decisions more accurate, repeatable, and aligned with product risk.

Detailed explanation, example and interview tip

A strong explanation of never type should cover its purpose, the problem it solves, when it is appropriate, and where it can mislead a team. In TypeScript, use it deliberately rather than as a checklist item: connect it to observable behavior, choose clear pass/fail evidence, and record assumptions so another engineer can reproduce the result.

Real-world example

During release planning, the team used never type to focus validation on the most important behavior and to communicate residual risk before deployment.

Interview tip

Answer in four parts: definition, suitable use case, limitation, and a concrete project example.

Beginner7 Years

13. How would you apply readonly types in a production TypeScript project?

Answer: Apply readonly types through an explicit, repeatable design: define the expected behavior, automate the highest-risk path, capture useful diagnostics, and verify the result against a stable oracle.

Detailed explanation, example and interview tip

In a production TypeScript project, start by identifying the risk that readonly types controls and the evidence needed to prove the behavior. Keep setup, action, verification, and cleanup separate; parameterize environment-specific values; and make failures explain the business impact. Run the smallest relevant check on each change, broader coverage in the pipeline, and review flaky or slow results rather than hiding them with retries.

Real-world example

A team introduced a focused readonly types check at the layer closest to the risk, attached diagnostics to failures, and used the result as a release signal instead of relying on manual confirmation.

Interview tip

Describe one trade-off, one failure mode, and one measurable outcome when discussing readonly types.

Beginner10+ Years

14. How would you apply strict mode in a production TypeScript project?

Answer: Apply strict mode through an explicit, repeatable design: define the expected behavior, automate the highest-risk path, capture useful diagnostics, and verify the result against a stable oracle.

Detailed explanation, example and interview tip

In a production TypeScript project, start by identifying the risk that strict mode controls and the evidence needed to prove the behavior. Keep setup, action, verification, and cleanup separate; parameterize environment-specific values; and make failures explain the business impact. Run the smallest relevant check on each change, broader coverage in the pipeline, and review flaky or slow results rather than hiding them with retries.

Real-world example

A team introduced a focused strict mode check at the layer closest to the risk, attached diagnostics to failures, and used the result as a release signal instead of relying on manual confirmation.

Interview tip

Describe one trade-off, one failure mode, and one measurable outcome when discussing strict mode.

Beginner10+ Years

15. What is module augmentation, and why does it matter in TypeScript?

Answer: module augmentation is a core TypeScript concept used to make testing decisions more accurate, repeatable, and aligned with product risk.

Detailed explanation, example and interview tip

A strong explanation of module augmentation should cover its purpose, the problem it solves, when it is appropriate, and where it can mislead a team. In TypeScript, use it deliberately rather than as a checklist item: connect it to observable behavior, choose clear pass/fail evidence, and record assumptions so another engineer can reproduce the result.

Real-world example

During release planning, the team used module augmentation to focus validation on the most important behavior and to communicate residual risk before deployment.

Interview tip

Answer in four parts: definition, suitable use case, limitation, and a concrete project example.

TypeScript interview questions for experienced testers

Intermediate5 Years Frequently asked

16. When would you use an interface versus a type alias in a test framework codebase?

Answer: Interfaces are best for object shapes that might be extended or merged (like page object or config contracts), while type aliases are more flexible for unions, tuples, and mapped types.

Detailed explanation, example and interview tip

Interfaces support declaration merging and are extended with 'extends', which fits well for evolving config or fixture contracts across files. Type aliases can express unions, intersections, and conditional types that interfaces cannot, making them better for modeling API response variants or literal string sets like environment names. In practice, teams often standardize on interfaces for public object contracts (page objects, DTOs) and types for unions/utility compositions, keeping consistency across the codebase rather than mixing arbitrarily.

typescript
1interface PageObject {
2 navigate(): Promise<void>;
3 isLoaded(): Promise<boolean>;
4}
5
6type ApiResponse<T> =
7 | { status: 'success'; data: T }
8 | { status: 'error'; message: string };

Real-world example

Standardizing on interfaces for page objects and types for API response unions eliminated inconsistent code review debates on a 15-person automation team.

Interview tip

Note declaration merging explicitly as the deciding factor — it's the concrete technical distinction interviewers probe for.

Intermediate5 Years Frequently asked

17. Give examples of utility types you've used in an automation framework, like Partial, Pick, or Omit.

Answer: Partial<T> makes all fields optional for building partial test fixtures, Pick<T, K> extracts a subset of fields for a lightweight DTO, and Omit<T, K> removes fields you don't want exposed, like excluding a password from a response type.

Detailed explanation, example and interview tip

Partial is especially useful for factory functions that build test data with sensible defaults, letting callers override just the fields relevant to their test case. Pick helps define narrow view-models, such as a search-result row derived from a much larger User type. Omit is common when modeling API responses that intentionally exclude sensitive fields, like Omit<User, 'password'>. Record<K, V> is another frequently used one for typing lookup maps such as environment-to-baseUrl configuration objects.

typescript
1interface User { id: number; name: string; email: string; password: string; }
2
3type SafeUser = Omit<User, 'password'>;
4type UserPreview = Pick<User, 'id' | 'name'>;
5
6function buildUser(overrides: Partial<User> = {}): User {
7 return { id: 1, name: 'Test User', email: 't@test.com', password: 'x', ...overrides };
8}

Real-world example

Using Partial<User> in a test data factory let 40+ tests override only the fields relevant to each scenario instead of duplicating full user objects.

Interview tip

Show Partial<T> in a factory function — it's the single most reused pattern in real TS test frameworks.

Intermediate3 Years Frequently asked

18. How would you apply type inference in a production TypeScript project?

Answer: Apply type inference through an explicit, repeatable design: define the expected behavior, automate the highest-risk path, capture useful diagnostics, and verify the result against a stable oracle.

Detailed explanation, example and interview tip

In a production TypeScript project, start by identifying the risk that type inference controls and the evidence needed to prove the behavior. Keep setup, action, verification, and cleanup separate; parameterize environment-specific values; and make failures explain the business impact. Run the smallest relevant check on each change, broader coverage in the pipeline, and review flaky or slow results rather than hiding them with retries.

Real-world example

A team introduced a focused type inference check at the layer closest to the risk, attached diagnostics to failures, and used the result as a release signal instead of relying on manual confirmation.

Interview tip

Describe one trade-off, one failure mode, and one measurable outcome when discussing type inference.

Intermediate3 Years Frequently asked

19. How would you apply intersection types in a production TypeScript project?

Answer: Apply intersection types through an explicit, repeatable design: define the expected behavior, automate the highest-risk path, capture useful diagnostics, and verify the result against a stable oracle.

Detailed explanation, example and interview tip

In a production TypeScript project, start by identifying the risk that intersection types controls and the evidence needed to prove the behavior. Keep setup, action, verification, and cleanup separate; parameterize environment-specific values; and make failures explain the business impact. Run the smallest relevant check on each change, broader coverage in the pipeline, and review flaky or slow results rather than hiding them with retries.

Real-world example

A team introduced a focused intersection types check at the layer closest to the risk, attached diagnostics to failures, and used the result as a release signal instead of relying on manual confirmation.

Interview tip

Describe one trade-off, one failure mode, and one measurable outcome when discussing intersection types.

Intermediate3 Years Frequently asked

20. What is type guards, and why does it matter in TypeScript?

Answer: type guards is a core TypeScript concept used to make testing decisions more accurate, repeatable, and aligned with product risk.

Detailed explanation, example and interview tip

A strong explanation of type guards should cover its purpose, the problem it solves, when it is appropriate, and where it can mislead a team. In TypeScript, use it deliberately rather than as a checklist item: connect it to observable behavior, choose clear pass/fail evidence, and record assumptions so another engineer can reproduce the result.

Real-world example

During release planning, the team used type guards to focus validation on the most important behavior and to communicate residual risk before deployment.

Interview tip

Answer in four parts: definition, suitable use case, limitation, and a concrete project example.

Intermediate5 Years Frequently asked

21. How would you apply generic constraints in a production TypeScript project?

Answer: Apply generic constraints through an explicit, repeatable design: define the expected behavior, automate the highest-risk path, capture useful diagnostics, and verify the result against a stable oracle.

Detailed explanation, example and interview tip

In a production TypeScript project, start by identifying the risk that generic constraints controls and the evidence needed to prove the behavior. Keep setup, action, verification, and cleanup separate; parameterize environment-specific values; and make failures explain the business impact. Run the smallest relevant check on each change, broader coverage in the pipeline, and review flaky or slow results rather than hiding them with retries.

Real-world example

A team introduced a focused generic constraints check at the layer closest to the risk, attached diagnostics to failures, and used the result as a release signal instead of relying on manual confirmation.

Interview tip

Describe one trade-off, one failure mode, and one measurable outcome when discussing generic constraints.

Intermediate5 Years Frequently asked

22. How would you apply typeof type queries in a production TypeScript project?

Answer: Apply typeof type queries through an explicit, repeatable design: define the expected behavior, automate the highest-risk path, capture useful diagnostics, and verify the result against a stable oracle.

Detailed explanation, example and interview tip

In a production TypeScript project, start by identifying the risk that typeof type queries controls and the evidence needed to prove the behavior. Keep setup, action, verification, and cleanup separate; parameterize environment-specific values; and make failures explain the business impact. Run the smallest relevant check on each change, broader coverage in the pipeline, and review flaky or slow results rather than hiding them with retries.

Real-world example

A team introduced a focused typeof type queries check at the layer closest to the risk, attached diagnostics to failures, and used the result as a release signal instead of relying on manual confirmation.

Interview tip

Describe one trade-off, one failure mode, and one measurable outcome when discussing typeof type queries.

Intermediate5 Years Frequently asked

23. What is indexed access types, and why does it matter in TypeScript?

Answer: indexed access types is a core TypeScript concept used to make testing decisions more accurate, repeatable, and aligned with product risk.

Detailed explanation, example and interview tip

A strong explanation of indexed access types should cover its purpose, the problem it solves, when it is appropriate, and where it can mislead a team. In TypeScript, use it deliberately rather than as a checklist item: connect it to observable behavior, choose clear pass/fail evidence, and record assumptions so another engineer can reproduce the result.

Real-world example

During release planning, the team used indexed access types to focus validation on the most important behavior and to communicate residual risk before deployment.

Interview tip

Answer in four parts: definition, suitable use case, limitation, and a concrete project example.

Intermediate7 Years Frequently asked

24. How would you apply conditional types in a production TypeScript project?

Answer: Apply conditional types through an explicit, repeatable design: define the expected behavior, automate the highest-risk path, capture useful diagnostics, and verify the result against a stable oracle.

Detailed explanation, example and interview tip

In a production TypeScript project, start by identifying the risk that conditional types controls and the evidence needed to prove the behavior. Keep setup, action, verification, and cleanup separate; parameterize environment-specific values; and make failures explain the business impact. Run the smallest relevant check on each change, broader coverage in the pipeline, and review flaky or slow results rather than hiding them with retries.

Real-world example

A team introduced a focused conditional types check at the layer closest to the risk, attached diagnostics to failures, and used the result as a release signal instead of relying on manual confirmation.

Interview tip

Describe one trade-off, one failure mode, and one measurable outcome when discussing conditional types.

Intermediate7 Years Frequently asked

25. How would you apply never type in a production TypeScript project?

Answer: Apply never type through an explicit, repeatable design: define the expected behavior, automate the highest-risk path, capture useful diagnostics, and verify the result against a stable oracle.

Detailed explanation, example and interview tip

In a production TypeScript project, start by identifying the risk that never type controls and the evidence needed to prove the behavior. Keep setup, action, verification, and cleanup separate; parameterize environment-specific values; and make failures explain the business impact. Run the smallest relevant check on each change, broader coverage in the pipeline, and review flaky or slow results rather than hiding them with retries.

Real-world example

A team introduced a focused never type check at the layer closest to the risk, attached diagnostics to failures, and used the result as a release signal instead of relying on manual confirmation.

Interview tip

Describe one trade-off, one failure mode, and one measurable outcome when discussing never type.

Intermediate7 Years Frequently asked

26. What is function overloads, and why does it matter in TypeScript?

Answer: function overloads is a core TypeScript concept used to make testing decisions more accurate, repeatable, and aligned with product risk.

Detailed explanation, example and interview tip

A strong explanation of function overloads should cover its purpose, the problem it solves, when it is appropriate, and where it can mislead a team. In TypeScript, use it deliberately rather than as a checklist item: connect it to observable behavior, choose clear pass/fail evidence, and record assumptions so another engineer can reproduce the result.

Real-world example

During release planning, the team used function overloads to focus validation on the most important behavior and to communicate residual risk before deployment.

Interview tip

Answer in four parts: definition, suitable use case, limitation, and a concrete project example.

Intermediate10+ Years Frequently asked

27. How would you apply enums versus literal unions in a production TypeScript project?

Answer: Apply enums versus literal unions through an explicit, repeatable design: define the expected behavior, automate the highest-risk path, capture useful diagnostics, and verify the result against a stable oracle.

Detailed explanation, example and interview tip

In a production TypeScript project, start by identifying the risk that enums versus literal unions controls and the evidence needed to prove the behavior. Keep setup, action, verification, and cleanup separate; parameterize environment-specific values; and make failures explain the business impact. Run the smallest relevant check on each change, broader coverage in the pipeline, and review flaky or slow results rather than hiding them with retries.

Real-world example

A team introduced a focused enums versus literal unions check at the layer closest to the risk, attached diagnostics to failures, and used the result as a release signal instead of relying on manual confirmation.

Interview tip

Describe one trade-off, one failure mode, and one measurable outcome when discussing enums versus literal unions.

Intermediate10+ Years Frequently asked

28. How would you apply module augmentation in a production TypeScript project?

Answer: Apply module augmentation through an explicit, repeatable design: define the expected behavior, automate the highest-risk path, capture useful diagnostics, and verify the result against a stable oracle.

Detailed explanation, example and interview tip

In a production TypeScript project, start by identifying the risk that module augmentation controls and the evidence needed to prove the behavior. Keep setup, action, verification, and cleanup separate; parameterize environment-specific values; and make failures explain the business impact. Run the smallest relevant check on each change, broader coverage in the pipeline, and review flaky or slow results rather than hiding them with retries.

Real-world example

A team introduced a focused module augmentation check at the layer closest to the risk, attached diagnostics to failures, and used the result as a release signal instead of relying on manual confirmation.

Interview tip

Describe one trade-off, one failure mode, and one measurable outcome when discussing module augmentation.

Intermediate10+ Years Frequently asked

29. What is satisfies operator, and why does it matter in TypeScript?

Answer: satisfies operator is a core TypeScript concept used to make testing decisions more accurate, repeatable, and aligned with product risk.

Detailed explanation, example and interview tip

A strong explanation of satisfies operator should cover its purpose, the problem it solves, when it is appropriate, and where it can mislead a team. In TypeScript, use it deliberately rather than as a checklist item: connect it to observable behavior, choose clear pass/fail evidence, and record assumptions so another engineer can reproduce the result.

Real-world example

During release planning, the team used satisfies operator to focus validation on the most important behavior and to communicate residual risk before deployment.

Interview tip

Answer in four parts: definition, suitable use case, limitation, and a concrete project example.

Intermediate5 Years

30. Why use TypeScript for an automation framework instead of plain JavaScript?

Answer: Compile-time safety on page objects, API payloads and fixtures, real IDE autocomplete, safe refactoring, and typed test data that prevents whole classes of runtime failures.

Detailed explanation, example and interview tip

Interfaces and generics let you type API responses so a renamed field breaks the build instead of a nightly run. Union types model test data variants, and strict null checks force explicit handling of optional elements. For frameworks, types are living documentation for page objects and fixtures; combined with path aliases and ts strict mode you get refactors that are mechanical rather than risky.

typescript
1interface Order { id: number; status: 'NEW' | 'PAID' | 'SHIPPED'; total: number }
2
3const order = await api.get<Order>('/orders/7');
4expect(order.status).toBe('PAID'); // typo in 'staus' fails at compile time

Real-world example

Typing API contracts caught a backend rename of total → amountTotal at build time, before the release run.

Interview tip

Frame types as failing earlier and cheaper — that is the argument managers buy.

Intermediate5 Years

31. When would you choose a union of string literals over an enum for something like environment names or test tags?

Answer: Union literal types are lighter-weight, don't emit any runtime JS, and work more naturally with plain string values from config files, whereas enums generate actual runtime objects and are better when you need reverse-mapping or namespacing.

Detailed explanation, example and interview tip

A string literal union like type Environment = 'dev' | 'staging' | 'prod' gives full compile-time checking with zero runtime footprint, and integrates cleanly with JSON config or environment variables that are naturally strings. Enums compile to real JS objects, which can be useful for iterating over values or when you want a distinct namespace (Environment.Prod), but they add bundle size and can behave unexpectedly with const enum in certain build tools. Most modern TypeScript style guides favor literal unions for simple fixed sets like tags or environments and reserve enums for genuinely enumerable, iterable domains.

typescript
1type Environment = 'dev' | 'staging' | 'prod';
2type TestTag = '@smoke' | '@regression' | '@critical';
3
4function getBaseUrl(env: Environment): string {
5 const urls: Record<Environment, string> = {
6 dev: 'https://dev.example.com',
7 staging: 'https://staging.example.com',
8 prod: 'https://example.com',
9 };
10 return urls[env];
11}

Real-world example

Switching test tags from an enum to string literal unions removed a runtime import that was breaking tree-shaking in the CI bundler, shaving seconds off every pipeline run.

Interview tip

Mention the zero-runtime-footprint aspect of literal unions — it signals you think about build/bundle implications, not just syntax preference.

Intermediate3 Years

32. What is interfaces versus type aliases, and why does it matter in TypeScript?

Answer: interfaces versus type aliases is a core TypeScript concept used to make testing decisions more accurate, repeatable, and aligned with product risk.

Detailed explanation, example and interview tip

A strong explanation of interfaces versus type aliases should cover its purpose, the problem it solves, when it is appropriate, and where it can mislead a team. In TypeScript, use it deliberately rather than as a checklist item: connect it to observable behavior, choose clear pass/fail evidence, and record assumptions so another engineer can reproduce the result.

Real-world example

During release planning, the team used interfaces versus type aliases to focus validation on the most important behavior and to communicate residual risk before deployment.

Interview tip

Answer in four parts: definition, suitable use case, limitation, and a concrete project example.

Intermediate5 Years

33. What is utility types, and why does it matter in TypeScript?

Answer: utility types is a core TypeScript concept used to make testing decisions more accurate, repeatable, and aligned with product risk.

Detailed explanation, example and interview tip

A strong explanation of utility types should cover its purpose, the problem it solves, when it is appropriate, and where it can mislead a team. In TypeScript, use it deliberately rather than as a checklist item: connect it to observable behavior, choose clear pass/fail evidence, and record assumptions so another engineer can reproduce the result.

Real-world example

During release planning, the team used utility types to focus validation on the most important behavior and to communicate residual risk before deployment.

Interview tip

Answer in four parts: definition, suitable use case, limitation, and a concrete project example.

Intermediate7 Years

34. What is discriminated unions, and why does it matter in TypeScript?

Answer: discriminated unions is a core TypeScript concept used to make testing decisions more accurate, repeatable, and aligned with product risk.

Detailed explanation, example and interview tip

A strong explanation of discriminated unions should cover its purpose, the problem it solves, when it is appropriate, and where it can mislead a team. In TypeScript, use it deliberately rather than as a checklist item: connect it to observable behavior, choose clear pass/fail evidence, and record assumptions so another engineer can reproduce the result.

Real-world example

During release planning, the team used discriminated unions to focus validation on the most important behavior and to communicate residual risk before deployment.

Interview tip

Answer in four parts: definition, suitable use case, limitation, and a concrete project example.

Intermediate10+ Years

35. What is declaration merging, and why does it matter in TypeScript?

Answer: declaration merging is a core TypeScript concept used to make testing decisions more accurate, repeatable, and aligned with product risk.

Detailed explanation, example and interview tip

A strong explanation of declaration merging should cover its purpose, the problem it solves, when it is appropriate, and where it can mislead a team. In TypeScript, use it deliberately rather than as a checklist item: connect it to observable behavior, choose clear pass/fail evidence, and record assumptions so another engineer can reproduce the result.

Real-world example

During release planning, the team used declaration merging to focus validation on the most important behavior and to communicate residual risk before deployment.

Interview tip

Answer in four parts: definition, suitable use case, limitation, and a concrete project example.

Advanced TypeScript interview questions

Advanced7 Years Frequently asked

36. How do you use generics to build a reusable page object or API client class?

Answer: Generics let a single class or function work with multiple types safely, so an API client can return a strongly-typed response for whatever endpoint's shape you pass in.

Detailed explanation, example and interview tip

Instead of writing a separate client method per entity or typing responses as 'any', a generic method like get<T>(path) lets callers specify the expected shape and get compile-time checked access to its fields. For page objects, generics help build reusable base classes — e.g., a generic Table<RowType> component wrapper that returns typed row data instead of untyped locators. This reduces duplication while still catching typos in field access at compile time rather than at runtime.

typescript
1class ApiClient {
2 async get<T>(path: string): Promise<T> {
3 const res = await fetch(`${this.baseUrl}${path}`);
4 return res.json() as Promise<T>;
5 }
6}
7
8interface User { id: number; email: string; }
9
10const client = new ApiClient();
11const user = await client.get<User>('/users/1');
12console.log(user.email); // type-checked

Real-world example

Introducing a generic ApiClient.get<T>() replaced dozens of duplicated, untyped fetch wrappers and immediately caught three places where tests accessed a renamed field.

Interview tip

Show the generic method signature live rather than just describing it — interviewers want to see you write get<T>(path: string): Promise<T> unprompted.

Advanced7 Years Frequently asked

37. What does strictNullChecks do, and why is it valuable in test automation code?

Answer: strictNullChecks makes null and undefined distinct types that must be explicitly handled, preventing runtime 'cannot read property of undefined' errors from locator/element lookups that silently return nothing.

Detailed explanation, example and interview tip

Without strictNullChecks, any type implicitly allows null/undefined, so a function like page.locator().textContent() that can return null compiles fine even if you access a property on it directly. With it enabled, TypeScript forces you to narrow the type first — via an if-check, optional chaining, or a non-null assertion when you're confident — before accessing properties. This catches an entire category of flaky test failures where an element wasn't found but the code proceeded as if it was, at compile time instead of during a CI run.

typescript
1// strictNullChecks: true
2async function getText(locator: Locator): Promise<string> {
3 const text = await locator.textContent(); // string | null
4 if (text === null) {
5 throw new Error('Expected text content but got null');
6 }
7 return text.trim();
8}

Real-world example

Enabling strictNullChecks on a legacy Playwright TS project surfaced 30+ places where element text was used without a null guard, several of which were causing intermittent CI failures.

Interview tip

Tie it directly to Playwright/Selenium locator APIs returning null — that's the most relevant real-world example for QA interviews.

Advanced10+ Years Frequently asked

38. How do you type an API client so response validation failures are caught at compile time, not just at runtime?

Answer: Define explicit interfaces for request/response payloads and pair them with a runtime schema validator like Zod, then infer the TypeScript type directly from that schema so compile-time types and runtime validation never drift apart.

Detailed explanation, example and interview tip

Hand-written interfaces alone don't protect you at runtime — the API can change without TypeScript knowing, since 'as T' assertions are just compiler trust, not verification. Using a library like Zod to define the schema once and inferring the TS type from it (z.infer<typeof schema>) means both compile-time typing and runtime parsing come from a single source of truth. Parsing the response with schema.parse(json) throws immediately if the API's actual shape doesn't match, turning silent contract-drift bugs into loud, early test failures instead of downstream assertion mysteries.

typescript
1import { z } from 'zod';
2
3const UserSchema = z.object({
4 id: z.number(),
5 email: z.string().email(),
6});
7type User = z.infer<typeof UserSchema>;
8
9async function getUser(id: number): Promise<User> {
10 const res = await fetch(`/users/${id}`);
11 return UserSchema.parse(await res.json());
12}

Real-world example

Adding Zod validation to an API test client caught a backend change where 'email' silently became nullable, which previously slipped through as a passing test with a stale interface.

Interview tip

Bring up schema-derived types (z.infer) as the fix for interface/runtime drift — it's a senior-level distinction interviewers rarely hear candidates articulate clearly.

Advanced3 Years Frequently asked

39. What is union types, and why does it matter in TypeScript?

Answer: union types is a core TypeScript concept used to make testing decisions more accurate, repeatable, and aligned with product risk.

Detailed explanation, example and interview tip

A strong explanation of union types should cover its purpose, the problem it solves, when it is appropriate, and where it can mislead a team. In TypeScript, use it deliberately rather than as a checklist item: connect it to observable behavior, choose clear pass/fail evidence, and record assumptions so another engineer can reproduce the result.

Real-world example

During release planning, the team used union types to focus validation on the most important behavior and to communicate residual risk before deployment.

Interview tip

Answer in four parts: definition, suitable use case, limitation, and a concrete project example.

Advanced5 Years Frequently asked

40. What is keyof operator, and why does it matter in TypeScript?

Answer: keyof operator is a core TypeScript concept used to make testing decisions more accurate, repeatable, and aligned with product risk.

Detailed explanation, example and interview tip

A strong explanation of keyof operator should cover its purpose, the problem it solves, when it is appropriate, and where it can mislead a team. In TypeScript, use it deliberately rather than as a checklist item: connect it to observable behavior, choose clear pass/fail evidence, and record assumptions so another engineer can reproduce the result.

Real-world example

During release planning, the team used keyof operator to focus validation on the most important behavior and to communicate residual risk before deployment.

Interview tip

Answer in four parts: definition, suitable use case, limitation, and a concrete project example.

Advanced7 Years Frequently asked

41. What is unknown versus any, and why does it matter in TypeScript?

Answer: unknown versus any is a core TypeScript concept used to make testing decisions more accurate, repeatable, and aligned with product risk.

Detailed explanation, example and interview tip

A strong explanation of unknown versus any should cover its purpose, the problem it solves, when it is appropriate, and where it can mislead a team. In TypeScript, use it deliberately rather than as a checklist item: connect it to observable behavior, choose clear pass/fail evidence, and record assumptions so another engineer can reproduce the result.

Real-world example

During release planning, the team used unknown versus any to focus validation on the most important behavior and to communicate residual risk before deployment.

Interview tip

Answer in four parts: definition, suitable use case, limitation, and a concrete project example.

Advanced10+ Years Frequently asked

42. What is strict mode, and why does it matter in TypeScript?

Answer: strict mode is a core TypeScript concept used to make testing decisions more accurate, repeatable, and aligned with product risk.

Detailed explanation, example and interview tip

A strong explanation of strict mode should cover its purpose, the problem it solves, when it is appropriate, and where it can mislead a team. In TypeScript, use it deliberately rather than as a checklist item: connect it to observable behavior, choose clear pass/fail evidence, and record assumptions so another engineer can reproduce the result.

Real-world example

During release planning, the team used strict mode to focus validation on the most important behavior and to communicate residual risk before deployment.

Interview tip

Answer in four parts: definition, suitable use case, limitation, and a concrete project example.

Advanced10+ Years

43. How does declaration merging let you extend a test runner's fixture types, like adding custom Playwright fixtures?

Answer: Declaration merging lets you add new properties to an existing interface (like Playwright's TestArgs) by re-declaring it elsewhere with the same name, so TypeScript combines both declarations into one type.

Detailed explanation, example and interview tip

TypeScript merges multiple interface declarations with the same name into a single interface with all combined members, which is how Playwright's test.extend() fixtures get proper typing — you declare a global augmentation of the base Fixtures interface with your custom fixture keys. This lets custom fixtures like an authenticated 'page' or a preconfigured 'apiClient' be fully type-checked and autocompleted in test files without modifying the library's own type definitions. It's an advanced pattern usually confined to a single fixtures.ts file to avoid scattering global augmentations across the codebase.

typescript
1// fixtures.ts
2import { test as base } from '@playwright/test';
3
4interface MyFixtures {
5 apiClient: ApiClient;
6}
7
8export const test = base.extend<MyFixtures>({
9 apiClient: async ({}, use) => {
10 await use(new ApiClient(process.env.BASE_URL!));
11 },
12});

Real-world example

Adding a typed apiClient fixture via declaration merging let 200+ test files call apiClient.get<T>() with full autocomplete instead of instantiating a client manually in every file.

Interview tip

Reference Playwright's own test.extend() pattern by name — it shows hands-on framework experience, not just abstract TS theory.

Advanced3 Years

44. How would you apply interfaces versus type aliases in a production TypeScript project?

Answer: Apply interfaces versus type aliases through an explicit, repeatable design: define the expected behavior, automate the highest-risk path, capture useful diagnostics, and verify the result against a stable oracle.

Detailed explanation, example and interview tip

In a production TypeScript project, start by identifying the risk that interfaces versus type aliases controls and the evidence needed to prove the behavior. Keep setup, action, verification, and cleanup separate; parameterize environment-specific values; and make failures explain the business impact. Run the smallest relevant check on each change, broader coverage in the pipeline, and review flaky or slow results rather than hiding them with retries.

Real-world example

A team introduced a focused interfaces versus type aliases check at the layer closest to the risk, attached diagnostics to failures, and used the result as a release signal instead of relying on manual confirmation.

Interview tip

Describe one trade-off, one failure mode, and one measurable outcome when discussing interfaces versus type aliases.

Advanced3 Years

45. How would you apply type guards in a production TypeScript project?

Answer: Apply type guards through an explicit, repeatable design: define the expected behavior, automate the highest-risk path, capture useful diagnostics, and verify the result against a stable oracle.

Detailed explanation, example and interview tip

In a production TypeScript project, start by identifying the risk that type guards controls and the evidence needed to prove the behavior. Keep setup, action, verification, and cleanup separate; parameterize environment-specific values; and make failures explain the business impact. Run the smallest relevant check on each change, broader coverage in the pipeline, and review flaky or slow results rather than hiding them with retries.

Real-world example

A team introduced a focused type guards check at the layer closest to the risk, attached diagnostics to failures, and used the result as a release signal instead of relying on manual confirmation.

Interview tip

Describe one trade-off, one failure mode, and one measurable outcome when discussing type guards.

Advanced3 Years

46. What is generics, and why does it matter in TypeScript?

Answer: generics is a core TypeScript concept used to make testing decisions more accurate, repeatable, and aligned with product risk.

Detailed explanation, example and interview tip

A strong explanation of generics should cover its purpose, the problem it solves, when it is appropriate, and where it can mislead a team. In TypeScript, use it deliberately rather than as a checklist item: connect it to observable behavior, choose clear pass/fail evidence, and record assumptions so another engineer can reproduce the result.

Real-world example

During release planning, the team used generics to focus validation on the most important behavior and to communicate residual risk before deployment.

Interview tip

Answer in four parts: definition, suitable use case, limitation, and a concrete project example.

Advanced5 Years

47. How would you apply utility types in a production TypeScript project?

Answer: Apply utility types through an explicit, repeatable design: define the expected behavior, automate the highest-risk path, capture useful diagnostics, and verify the result against a stable oracle.

Detailed explanation, example and interview tip

In a production TypeScript project, start by identifying the risk that utility types controls and the evidence needed to prove the behavior. Keep setup, action, verification, and cleanup separate; parameterize environment-specific values; and make failures explain the business impact. Run the smallest relevant check on each change, broader coverage in the pipeline, and review flaky or slow results rather than hiding them with retries.

Real-world example

A team introduced a focused utility types check at the layer closest to the risk, attached diagnostics to failures, and used the result as a release signal instead of relying on manual confirmation.

Interview tip

Describe one trade-off, one failure mode, and one measurable outcome when discussing utility types.

Advanced5 Years

48. How would you apply indexed access types in a production TypeScript project?

Answer: Apply indexed access types through an explicit, repeatable design: define the expected behavior, automate the highest-risk path, capture useful diagnostics, and verify the result against a stable oracle.

Detailed explanation, example and interview tip

In a production TypeScript project, start by identifying the risk that indexed access types controls and the evidence needed to prove the behavior. Keep setup, action, verification, and cleanup separate; parameterize environment-specific values; and make failures explain the business impact. Run the smallest relevant check on each change, broader coverage in the pipeline, and review flaky or slow results rather than hiding them with retries.

Real-world example

A team introduced a focused indexed access types check at the layer closest to the risk, attached diagnostics to failures, and used the result as a release signal instead of relying on manual confirmation.

Interview tip

Describe one trade-off, one failure mode, and one measurable outcome when discussing indexed access types.

Advanced5 Years

49. What is mapped types, and why does it matter in TypeScript?

Answer: mapped types is a core TypeScript concept used to make testing decisions more accurate, repeatable, and aligned with product risk.

Detailed explanation, example and interview tip

A strong explanation of mapped types should cover its purpose, the problem it solves, when it is appropriate, and where it can mislead a team. In TypeScript, use it deliberately rather than as a checklist item: connect it to observable behavior, choose clear pass/fail evidence, and record assumptions so another engineer can reproduce the result.

Real-world example

During release planning, the team used mapped types to focus validation on the most important behavior and to communicate residual risk before deployment.

Interview tip

Answer in four parts: definition, suitable use case, limitation, and a concrete project example.

Advanced7 Years

50. How would you apply discriminated unions in a production TypeScript project?

Answer: Apply discriminated unions through an explicit, repeatable design: define the expected behavior, automate the highest-risk path, capture useful diagnostics, and verify the result against a stable oracle.

Detailed explanation, example and interview tip

In a production TypeScript project, start by identifying the risk that discriminated unions controls and the evidence needed to prove the behavior. Keep setup, action, verification, and cleanup separate; parameterize environment-specific values; and make failures explain the business impact. Run the smallest relevant check on each change, broader coverage in the pipeline, and review flaky or slow results rather than hiding them with retries.

Real-world example

A team introduced a focused discriminated unions check at the layer closest to the risk, attached diagnostics to failures, and used the result as a release signal instead of relying on manual confirmation.

Interview tip

Describe one trade-off, one failure mode, and one measurable outcome when discussing discriminated unions.

Advanced7 Years

51. How would you apply function overloads in a production TypeScript project?

Answer: Apply function overloads through an explicit, repeatable design: define the expected behavior, automate the highest-risk path, capture useful diagnostics, and verify the result against a stable oracle.

Detailed explanation, example and interview tip

In a production TypeScript project, start by identifying the risk that function overloads controls and the evidence needed to prove the behavior. Keep setup, action, verification, and cleanup separate; parameterize environment-specific values; and make failures explain the business impact. Run the smallest relevant check on each change, broader coverage in the pipeline, and review flaky or slow results rather than hiding them with retries.

Real-world example

A team introduced a focused function overloads check at the layer closest to the risk, attached diagnostics to failures, and used the result as a release signal instead of relying on manual confirmation.

Interview tip

Describe one trade-off, one failure mode, and one measurable outcome when discussing function overloads.

Advanced7 Years

52. What is readonly types, and why does it matter in TypeScript?

Answer: readonly types is a core TypeScript concept used to make testing decisions more accurate, repeatable, and aligned with product risk.

Detailed explanation, example and interview tip

A strong explanation of readonly types should cover its purpose, the problem it solves, when it is appropriate, and where it can mislead a team. In TypeScript, use it deliberately rather than as a checklist item: connect it to observable behavior, choose clear pass/fail evidence, and record assumptions so another engineer can reproduce the result.

Real-world example

During release planning, the team used readonly types to focus validation on the most important behavior and to communicate residual risk before deployment.

Interview tip

Answer in four parts: definition, suitable use case, limitation, and a concrete project example.

Advanced10+ Years

53. How would you apply declaration merging in a production TypeScript project?

Answer: Apply declaration merging through an explicit, repeatable design: define the expected behavior, automate the highest-risk path, capture useful diagnostics, and verify the result against a stable oracle.

Detailed explanation, example and interview tip

In a production TypeScript project, start by identifying the risk that declaration merging controls and the evidence needed to prove the behavior. Keep setup, action, verification, and cleanup separate; parameterize environment-specific values; and make failures explain the business impact. Run the smallest relevant check on each change, broader coverage in the pipeline, and review flaky or slow results rather than hiding them with retries.

Real-world example

A team introduced a focused declaration merging check at the layer closest to the risk, attached diagnostics to failures, and used the result as a release signal instead of relying on manual confirmation.

Interview tip

Describe one trade-off, one failure mode, and one measurable outcome when discussing declaration merging.

Advanced10+ Years

54. How would you apply satisfies operator in a production TypeScript project?

Answer: Apply satisfies operator through an explicit, repeatable design: define the expected behavior, automate the highest-risk path, capture useful diagnostics, and verify the result against a stable oracle.

Detailed explanation, example and interview tip

In a production TypeScript project, start by identifying the risk that satisfies operator controls and the evidence needed to prove the behavior. Keep setup, action, verification, and cleanup separate; parameterize environment-specific values; and make failures explain the business impact. Run the smallest relevant check on each change, broader coverage in the pipeline, and review flaky or slow results rather than hiding them with retries.

Real-world example

A team introduced a focused satisfies operator check at the layer closest to the risk, attached diagnostics to failures, and used the result as a release signal instead of relying on manual confirmation.

Interview tip

Describe one trade-off, one failure mode, and one measurable outcome when discussing satisfies operator.

Interview questions by subject

Want to search across every subject? Open the full question bank.