TypeScript Professional Standards & Ethics 4 — Questions and Answers
Question 1: What is the professional standard for handling deprecated TypeScript APIs in a shared codebase?
- Remove them immediately without notice
- Mark them with `@deprecated` JSDoc, communicate a migration path, and phase them out gradually (Correct answer)
- Keep them indefinitely to avoid breaking changes
- Delete them only when a new hire joins the project
Correct answer: Mark them with `@deprecated` JSDoc, communicate a migration path, and phase them out gradually
The professional approach uses `@deprecated` annotations and provides a clear migration path before removal to respect downstream consumers.
Question 2: A developer is tasked with migrating a JavaScript codebase to TypeScript. They convert all unresolvable types to `any` to pass CI quickly. This approach violates which standard?
- Continuous integration best practices
- The principle of honest representation of code quality and completeness (Correct answer)
- ECMAScript module resolution
- Package manager versioning policy
Correct answer: The principle of honest representation of code quality and completeness
Masking type problems with `any` misrepresents migration progress and creates hidden technical debt that misleads stakeholders.
Question 3: Which TypeScript-specific practice upholds the professional principle of 'least privilege' in API design?
- Exporting every type and interface from a module
- Using `private`, `protected`, and minimizing public surface area (Correct answer)
- Using `any` for all public method parameters
- Declaring all class properties as public for easy testing
Correct answer: Using `private`, `protected`, and minimizing public surface area
Restricting visibility with `private` and `protected` limits the public API surface, reducing coupling and accidental misuse.
Question 4: A developer notices a teammate using AI-generated TypeScript code without reviewing it for correctness. What is the professional responsibility here?
- Say nothing since AI tools are officially approved
- Raise the concern: all code, regardless of source, must be reviewed and understood before merging (Correct answer)
- Report the teammate to HR immediately
- Switch to a different AI tool
Correct answer: Raise the concern: all code, regardless of source, must be reviewed and understood before merging
Every developer is accountable for code they commit, and AI-generated code must be reviewed and understood just like any other contribution.
Question 5: When writing TypeScript for a financial application, which practice best meets professional accuracy standards?
- Use `number` for all monetary values
- Use branded types or a Decimal library to prevent floating-point precision errors in monetary calculations (Correct answer)
- Use `string` for all currency amounts
- Round all values to two decimal places using toFixed()
Correct answer: Use branded types or a Decimal library to prevent floating-point precision errors in monetary calculations
Floating-point arithmetic is unsuitable for money; branded types or a Decimal library ensure precision and prevent financial calculation errors.
Question 6: What professional obligation does a TypeScript library author have when a security vulnerability is found in their published package?
- Quietly fix it in the next scheduled release
- Publish a patch immediately, issue a security advisory, and notify users via all available channels (Correct answer)
- Remove the package from the registry permanently
- Wait for users to report exploitation before acting
Correct answer: Publish a patch immediately, issue a security advisory, and notify users via all available channels
Responsible disclosure requires prompt patching and transparent communication so downstream users can protect themselves quickly.
Question 7: A developer uses the `as` keyword in TypeScript to force a type assertion that bypasses compile-time checks on user input. This is professionally problematic because:
- Type assertions slow down compilation
- It overrides the type system's safety guarantees, potentially allowing invalid data to reach business logic (Correct answer)
- It is not valid TypeScript syntax in strict mode
- It forces a full recompile of dependent modules
Correct answer: It overrides the type system's safety guarantees, potentially allowing invalid data to reach business logic
Forcing type assertions on user input bypasses runtime safety, meaning malformed data can propagate unchecked through the application.
What is the professional standard for handling deprecated TypeScript APIs in a shared codebase?