Question presented to candidate: "Your team is starting a new project and someone asks why we would use TypeScript instead of plain JavaScript. What is TypeScript, what does it actually give us, and what does it cost?"
What a strong answer should cover:
- TypeScript is JavaScript plus a static type system:
tscchecks types before the code runs, then erases them and emits plain JavaScript - Concrete bugs it catches that JavaScript runs anyway: property typos (
NaN), wrong arguments, missing fields, possibly-undefinedvalues - Type erasure: no run-time cost and no run-time checking, so data at trust boundaries (JSON, network) still needs validation
- Tooling and refactoring benefits: autocomplete, safe renames, signatures as documentation; structural typing and gradual adoption
- Honest costs: a build or check step (Node.js type stripping does not type-check), learning curve, false confidence from
anyandas, and the fact that plaintscstill emits on errors unlessnoEmitOnErroris set
Code / implementation expected: Optional β a small typed function showing an error JavaScript would only reveal at run time.