TypeScript Professional Standards & Ethics 2 — Questions and Answers
Question 1: A developer discovers that a third-party TypeScript library used in production secretly collects user telemetry without disclosure. What is the most ethical course of action?
- Continue using it since it's open source
- Remove the library and report the issue to the team and stakeholders (Correct answer)
- Disable telemetry via config and keep using it
- Ignore it if the app performance is fine
Correct answer: Remove the library and report the issue to the team and stakeholders
Undisclosed data collection violates user privacy and must be addressed by removing the dependency and notifying relevant parties.
Question 2: Which TypeScript compiler option enforces that all code paths in a function return a value, helping prevent unintentional undefined returns?
- strict
- noImplicitAny
- noImplicitReturns (Correct answer)
- strictNullChecks
Correct answer: noImplicitReturns
`noImplicitReturns` causes the compiler to error when any code path in a function does not explicitly return a value.
Question 3: A TypeScript developer reuses a colleague's code in a new open-source project without attribution. This violates which professional principle?
- Encapsulation
- Intellectual property and attribution standards (Correct answer)
- Type safety guidelines
- Dependency injection principles
Correct answer: Intellectual property and attribution standards
Proper attribution of others' work is an ethical obligation and may also be a legal requirement under certain licenses.
Question 4: When a TypeScript codebase uses `any` extensively to meet a deadline, what ethical concern does this create?
- It reduces bundle size unnecessarily
- It transfers future risk and maintenance burden to others without disclosure (Correct answer)
- It automatically disables linting rules
- It conflicts with ECMAScript standards
Correct answer: It transfers future risk and maintenance burden to others without disclosure
Widespread `any` usage accumulates technical debt that will burden future maintainers, which should be disclosed and planned for.
Question 5: A developer is asked to write TypeScript types for an API that handles medical records. Which practice is most critical from a professional standards perspective?
- Use loose types to allow flexibility
- Use strict, well-documented types with clear nullability (Correct answer)
- Generate types automatically from any available source
- Defer typing until after the feature ships
Correct answer: Use strict, well-documented types with clear nullability
Medical data requires strict, well-documented type definitions to prevent errors and meet regulatory standards like HIPAA.
Question 6: Which behavior demonstrates professional responsibility when a TypeScript PR review reveals a security flaw?
- Approve the PR to avoid conflict
- Merge and file a follow-up ticket
- Block the PR, document the flaw clearly, and suggest a fix (Correct answer)
- Rewrite the entire module yourself
Correct answer: Block the PR, document the flaw clearly, and suggest a fix
Blocking a PR with clear documentation of the security issue and a suggested remedy is the professionally responsible action.
Question 7: What does enabling `strictPropertyInitialization` in TypeScript enforce that relates to professional coding standards?
- That all properties must be optional
- That class properties are initialized in the constructor or declared with a definite assignment assertion (Correct answer)
- That all interfaces must match class signatures exactly
- That readonly properties cannot be reassigned anywhere
Correct answer: That class properties are initialized in the constructor or declared with a definite assignment assertion
`strictPropertyInitialization` ensures class properties are properly initialized, preventing runtime errors from undefined property access.
A developer discovers that a third-party TypeScript library used in production secretly collects user telemetry without disclosure.
What is the most ethical course of action?