TypeScript Professional Standards & Ethics 3 — Questions and Answers
Question 1: A TypeScript developer is asked to add tracking code that logs all user keystrokes without the user's knowledge. The professional response is to:
- Implement it using an obfuscated module
- Refuse and escalate the ethical concern to management or legal (Correct answer)
- Implement it only in the production build
- Add it behind an undocumented feature flag
Correct answer: Refuse and escalate the ethical concern to management or legal
Implementing covert keylogging violates user privacy laws and professional ethics; the developer must refuse and escalate.
Question 2: Which TypeScript pattern best demonstrates the professional value of writing self-documenting code?
- Using single-letter generic type parameters everywhere
- Defining named type aliases and interfaces with descriptive names (Correct answer)
- Casting to `any` with inline comments
- Using `as unknown as T` for all type assertions
Correct answer: Defining named type aliases and interfaces with descriptive names
Descriptive type aliases and interfaces serve as living documentation, making code intent clear without requiring external comments.
Question 3: A developer ships TypeScript code with known `@ts-ignore` suppressions in payment processing logic. This represents a failure of:
- Aesthetic coding standards
- Due diligence and professional accountability in safety-critical code (Correct answer)
- Performance optimization practices
- Module resolution conventions
Correct answer: Due diligence and professional accountability in safety-critical code
Suppressing TypeScript errors in payment code bypasses safety checks and represents a failure of professional accountability.
Question 4: What is the ethical implication of publishing a TypeScript package with misleading version numbers that break semver conventions?
- It speeds up adoption
- It deceives dependent teams and can cause unexpected production breakages (Correct answer)
- It is acceptable for pre-release packages
- It has no real impact on downstream users
Correct answer: It deceives dependent teams and can cause unexpected production breakages
Violating semantic versioning breaks trust with the developer community and can silently break dependent applications.
Question 5: A junior developer hardcodes API keys directly in a TypeScript source file and commits it to a public repo. What professional responsibility did they fail?
- Following naming conventions
- Protecting sensitive credentials and understanding security fundamentals (Correct answer)
- Writing unit tests for the API client
- Using environment-specific tsconfig files
Correct answer: Protecting sensitive credentials and understanding security fundamentals
Hardcoding and exposing secrets in source control is a critical security failure that every developer is professionally responsible to avoid.
Question 6: Which of the following best reflects the professional use of TypeScript's `readonly` modifier?
- Applying it only to string properties
- Using it to explicitly communicate and enforce immutability intent to other developers (Correct answer)
- Replacing all `const` declarations with `readonly`
- Using it only in test files
Correct answer: Using it to explicitly communicate and enforce immutability intent to other developers
`readonly` makes immutability intent explicit and compiler-enforced, which is a hallmark of professional, communicative code.
Question 7: When a developer writes TypeScript that passes all tests but knowingly circumvents an accessibility requirement for users with disabilities, this violates:
- Type coverage thresholds
- Professional ethics and potentially ADA/WCAG legal standards (Correct answer)
- Compiler strict mode settings
- ESLint plugin rules
Correct answer: Professional ethics and potentially ADA/WCAG legal standards
Excluding users with disabilities is an ethical violation and may breach legal standards such as the ADA and WCAG guidelines.
A TypeScript developer is asked to add tracking code that logs all user keystrokes without the user's knowledge.
The professional response is to: