Q53. What is the difference between compile-time safety and correctness?
Compile-time safety checks that code conforms to its declared types, but types can be wrong, assertions can be unsafe, and business logic can be incorrect while type-correct. Runtime tests, validation, security review, and observability remain necessary.
TypeScript can verify that a discount is a number, but not that a business rule applied the correct discount unless the logic and tests encode that rule.
Note
Interview approach: define the concept, explain why it matters, then mention one trade-off or limitation.
TypeScript concept
// Illustrative TypeScript contract
type Identifier = string;
const id: Identifier = "item-1";💡 The example demonstrates the compile-time contract discussed in this question.
Key Takeaways
- Explain the concept in your own words.
- Know the practical trade-off and its limits.
- Use a small example to demonstrate the idea.
Knowledge Check
Can type-correct code still contain a logic bug?