TypeScript Communication & Stakeholder Relations 3 — Questions and Answers
Question 1: A designer unfamiliar with TypeScript asks what a `type` alias is. Which analogy best communicates the concept?
- A type alias is like a runtime class that creates objects
- A type alias is like a nickname for a data shape, helping developers refer to complex types by a meaningful name (Correct answer)
- A type alias compiles to a JavaScript variable at runtime
- A type alias is a way to import external libraries
Correct answer: A type alias is like a nickname for a data shape, helping developers refer to complex types by a meaningful name
Type aliases give complex type expressions a reusable, descriptive name, improving readability without adding any runtime code.
Question 2: A team lead notices that developers are using `// @ts-ignore` frequently in the codebase. What should they communicate to the team?
- `@ts-ignore` is a best practice for handling third-party library issues
- Frequent use of `@ts-ignore` suppresses type errors without fixing them, masking bugs and undermining TypeScript's value (Correct answer)
- `@ts-ignore` improves build performance by skipping checks
- `@ts-ignore` is equivalent to using the `any` type
Correct answer: Frequent use of `@ts-ignore` suppresses type errors without fixing them, masking bugs and undermining TypeScript's value
Over-relying on `@ts-ignore` hides real type issues and defeats the purpose of using TypeScript, and `@ts-expect-error` with a comment is preferable when suppression is truly necessary.
Question 3: A stakeholder asks why the team chose TypeScript over JavaScript for a large-scale project. Which reason is most compelling from a team collaboration perspective?
- TypeScript runs faster than JavaScript in all environments
- TypeScript enables multiple teams to work on the same codebase with explicit contracts, reducing integration bugs (Correct answer)
- TypeScript eliminates the need for unit tests
- TypeScript is required by all modern browsers
Correct answer: TypeScript enables multiple teams to work on the same codebase with explicit contracts, reducing integration bugs
Explicit types serve as self-documenting contracts between teams, making it safer for multiple developers to change shared code without breaking consumers.
Question 4: A developer wants to deprecate a utility function. What TypeScript mechanism best communicates this to other team members without breaking existing code?
- Delete the function immediately
- Mark the function with a `@deprecated` JSDoc tag so IDEs show a strikethrough and warning to callers (Correct answer)
- Rename the function to `_oldFunction`
- Add a console.warn inside the function body only
Correct answer: Mark the function with a `@deprecated` JSDoc tag so IDEs show a strikethrough and warning to callers
The `@deprecated` JSDoc tag causes IDEs to visually flag usages and show a warning, alerting developers to migrate without breaking the build.
Question 5: A QA engineer asks how TypeScript discriminated unions help catch bugs. What is the best explanation?
- Discriminated unions prevent all runtime errors in switch statements
- They allow TypeScript to narrow types based on a shared literal property, and the compiler warns if not all cases are handled (Correct answer)
- Discriminated unions are only useful for styling code
- They replace the need for unit tests on conditional logic
Correct answer: They allow TypeScript to narrow types based on a shared literal property, and the compiler warns if not all cases are handled
TypeScript uses the discriminant property to narrow the union in each branch, and with `never` exhaustiveness checks, the compiler alerts developers to unhandled cases.
Question 6: A client asks for an estimate on migrating a JavaScript project to TypeScript. What should you communicate about incremental migration?
- Migration must be done all at once or TypeScript will not compile
- TypeScript supports incremental migration with `allowJs`, letting teams convert files gradually while maintaining a working build (Correct answer)
- JavaScript files must be deleted before TypeScript can be added
- Only new files can be TypeScript; existing files must stay JavaScript forever
Correct answer: TypeScript supports incremental migration with `allowJs`, letting teams convert files gradually while maintaining a working build
The `allowJs` compiler option lets TypeScript and JavaScript coexist in one project, so teams can migrate file by file without a big-bang rewrite.
Question 7: During sprint planning, a developer raises that a third-party library lacks TypeScript types. How should you address this with the team?
- Avoid using the library entirely
- Install community-maintained `@types/` packages, or write a local declaration file to provide types without rewriting the library (Correct answer)
- Use `require()` instead of `import` to bypass the type issue
- Disable TypeScript for all files that use the library
Correct answer: Install community-maintained `@types/` packages, or write a local declaration file to provide types without rewriting the library
The DefinitelyTyped repository provides `@types/` packages for most popular libraries, and a `.d.ts` declaration file is a lightweight fallback for uncovered libraries.
A designer unfamiliar with TypeScript asks what a `type` alias is.
Which analogy best communicates the concept?