Glossary / TypeScript
TypeScript
TypeScript is a typed programming language and toolchain that builds on JavaScript with static type syntax and analysis. Its types are primarily erased at runtime: TypeScript helps detect classes of errors during development, but it does not automatically validate external data or change JavaScript runtime semantics.
Type checking and emit
The compiler parses TypeScript, checks assignability and other static rules, and can emit JavaScript and declaration files. With noEmit, another tool such as a bundler handles transformation while tsc checks types. target selects emitted syntax; lib supplies type declarations for built-in APIs but does not provide implementations. module and moduleResolution must match the runtime/bundler contract.
TypeScript is structurally typed: values are generally compatible based on members, with special rules for classes, private/protected members, variance, and excess property checks. Types such as interfaces and type aliases disappear at runtime. Assertions (as X) do not perform validation. any disables checking across boundaries; unknown requires narrowing before use.
Engineering guidance
Use strict compiler options for new code, model external input as unknown, and validate data at runtime. Avoid overusing assertions, any, and overly complex conditional types that reduce maintainability. Define package exports and declaration output together. Treat type changes as API changes and test declarations from a consumer fixture when publishing libraries.
Interview questions
- Are TypeScript types available at runtime? Usually not; most are erased during emit.
- Does
as Uservalidate JSON? No; it only changes the compiler's belief. - What does
libdo? Adds type declarations for APIs; it does not polyfill them. - What is structural typing? Compatibility is based largely on member shape rather than nominal names.
- How validate an API response? Parse/validate at runtime with guards or schema libraries, then use the resulting narrowed type.