TypeScript Leadership & Professional Development 4 — Questions and Answers
Question 1: A TypeScript project lead wants to standardize error handling across microservices. What pattern best leverages TypeScript's type system for this?
- Define a discriminated union Result type (Success | Failure) so callers must handle both cases (Correct answer)
- Use try/catch everywhere and type errors as 'any'
- Throw custom Error subclasses and rely on documentation for handling
- Return null for failures and let callers check for null
Correct answer: Define a discriminated union Result type (Success | Failure) so callers must handle both cases
A Result discriminated union makes error handling a type-checked contract, preventing silent error swallowing.
Question 2: A team lead discovers that developers are duplicating type definitions across multiple feature modules. What refactoring strategy should be prioritized?
- Extract common types into a shared types barrel file or package and import from there (Correct answer)
- Accept duplication as a team standard to keep modules independent
- Use 'any' instead of the duplicated types to reduce code
- Copy the types to each file that needs them using automated scripts
Correct answer: Extract common types into a shared types barrel file or package and import from there
Centralizing types in a shared barrel eliminates duplication and creates a single source of truth for type contracts.
Question 3: When conducting a TypeScript technical interview, which question best evaluates a candidate's practical understanding of the type system?
- 'Explain the difference between structural and nominal typing and give an example of when this matters in TypeScript' (Correct answer)
- 'What is the syntax for declaring a variable in TypeScript?'
- 'Name all the primitive types in TypeScript'
- 'Have you used TypeScript before?'
Correct answer: 'Explain the difference between structural and nominal typing and give an example of when this matters in TypeScript'
Questions about structural typing assess deep understanding of how TypeScript uniquely differs from other statically-typed languages.
Question 4: A tech lead needs to evaluate whether to adopt a new TypeScript library for state management. Which criterion is most important from a professional due-diligence perspective?
- Quality of TypeScript typings, active maintenance, and compatibility with the team's strict tsconfig settings (Correct answer)
- Number of GitHub stars and how recently it was created
- Whether the library author is well-known in the community
- Whether it has a live demo on its website
Correct answer: Quality of TypeScript typings, active maintenance, and compatibility with the team's strict tsconfig settings
Type quality, maintenance status, and tsconfig compatibility directly affect the team's ability to use the library safely long-term.
Question 5: A developer on your team is blocked because TypeScript's type inference cannot determine the return type of a complex recursive function. What is the best resolution?
- Add an explicit return type annotation to break the inference cycle and document why it is needed (Correct answer)
- Wrap the function in a try/catch and return 'any'
- Disable TypeScript checking for that file with @ts-nocheck
- Rewrite the function as a class to force explicit types
Correct answer: Add an explicit return type annotation to break the inference cycle and document why it is needed
Explicit return type annotations resolve inference limitations and serve as documentation for complex function signatures.
Question 6: A TypeScript team is adopting test-driven development. Which approach ensures tests and implementation share the same type contracts?
- Write tests in TypeScript using the same types as production code, letting the compiler catch contract mismatches (Correct answer)
- Write tests in plain JavaScript to avoid TypeScript overhead in the test suite
- Generate types for tests separately from production types
- Use 'as unknown as SomeType' in tests to bypass strict type checking
Correct answer: Write tests in TypeScript using the same types as production code, letting the compiler catch contract mismatches
TypeScript tests sharing production types means the compiler validates contract adherence before tests even run.
Question 7: A team lead is setting up ESLint with TypeScript. Which plugin combination provides the most comprehensive TypeScript-aware linting?
- @typescript-eslint/parser with @typescript-eslint/eslint-plugin and type-aware rules enabled (Correct answer)
- Standard ESLint rules without any TypeScript-specific plugins
- Prettier alone for formatting without linting
- TSLint (deprecated) for maximum TypeScript compatibility
Correct answer: @typescript-eslint/parser with @typescript-eslint/eslint-plugin and type-aware rules enabled
@typescript-eslint integrates ESLint with TypeScript's type checker, enabling rules that catch issues pure syntax linting cannot.
A TypeScript project lead wants to standardize error handling across microservices.
What pattern best leverages TypeScript's type system for this?