TypeScript Risk Assessment & Management 3 — Questions and Answers
Question 1: Which TypeScript utility type is best suited to safely construct a partial update payload, reducing the risk of accidentally omitting required fields in API calls?
- Partial<T> (Correct answer)
- Required<T>
- Readonly<T>
- Omit<T, K>
Correct answer: Partial<T>
Partial<T> makes all properties optional, which is appropriate for patch/update payloads where only changed fields need to be sent.
Question 2: What risk does enabling 'declaration: true' without also enabling 'declarationMap' introduce for library consumers?
- Consumers cannot trace type definitions back to source, making debugging harder (Correct answer)
- The library will not compile at all
- Tree-shaking becomes impossible
- Bundlers will duplicate module imports
Correct answer: Consumers cannot trace type definitions back to source, making debugging harder
Without declarationMap, the .d.ts files lack source mapping, so consumers cannot jump to the original TypeScript source when debugging type issues.
Question 3: A team uses structural typing and finds two unrelated interfaces accidentally satisfy each other. What risk does this create?
- Functions may silently accept wrong object types, masking logical errors (Correct answer)
- The compiler will refuse to compile the project
- Generic constraints will throw at runtime
- Module resolution will fail
Correct answer: Functions may silently accept wrong object types, masking logical errors
TypeScript's structural typing means any object with matching shape is accepted, so logically different types can be accidentally interchangeable without error.
Question 4: Which technique most effectively reduces the risk of breaking changes when refactoring a public TypeScript API?
- Using branded/nominal types to prevent implicit substitution between similar shapes (Correct answer)
- Removing all interfaces and using classes only
- Enabling allowSyntheticDefaultImports
- Switching from namespaces to global variables
Correct answer: Using branded/nominal types to prevent implicit substitution between similar shapes
Branded types add a unique tag that prevents structurally similar types from being used interchangeably, catching misuse at compile time during refactoring.
Question 5: When a TypeScript project uses 'paths' aliases in tsconfig, what deployment risk must be mitigated?
- Bundlers and Node.js runtimes do not natively resolve paths aliases, requiring additional configuration (Correct answer)
- Path aliases cause circular import errors by default
- The compiler ignores the paths setting at runtime
- Aliases break source maps in all environments
Correct answer: Bundlers and Node.js runtimes do not natively resolve paths aliases, requiring additional configuration
tsconfig paths are a compile-time convenience; runtimes like Node.js and many bundlers need separate plugins or tools to resolve the same aliases.
Question 6: What is the primary risk of using 'Function' as a parameter type instead of a specific function signature?
- Callers can pass any function regardless of arity or return type, hiding contract violations (Correct answer)
- It prevents the function from being called at all
- It causes the TypeScript compiler to emit JavaScript errors
- It disables overload resolution for the parameter
Correct answer: Callers can pass any function regardless of arity or return type, hiding contract violations
The Function type does not enforce argument count or types, so incorrect callbacks or handlers can be passed without a compile-time error.
Question 7: Which risk does enabling 'isolatedModules' in tsconfig help surface early in a TypeScript project?
- It flags constructs that cannot be safely transpiled file-by-file, catching issues before using fast single-file compilers like esbuild (Correct answer)
- It prevents any module from importing another
- It forces all files to use CommonJS format
- It disables type checking across module boundaries
Correct answer: It flags constructs that cannot be safely transpiled file-by-file, catching issues before using fast single-file compilers like esbuild
isolatedModules errors on patterns like const enum or namespace merges that require cross-file analysis, ensuring compatibility with transpile-only tools.
Which TypeScript utility type is best suited to safely construct a partial update payload, reducing the risk of accidentally omitting required fields in API calls?