Everything you need to know about TS
TypeScript (.ts) is JavaScript with static types - a superset created by Anders Hejlsberg (also of C# fame) at Microsoft in 2012. Every valid JavaScript file is valid TypeScript, but TypeScript adds optional type annotations that catch entire classes of bugs at compile time. Today TS dominates serious JavaScript development.
How it works under the hood
- Compile-time only. TypeScript types are erased at compile time - the runtime sees plain JavaScript. There's no runtime type-checking unless you add it (Zod, io-ts).
- Structural typing. Types match by shape, not by name. If two interfaces have the same properties, they're interchangeable.
- Type inference. TypeScript infers types from usage - you only need annotations for function signatures and complex generics.
- Strictness levels. `tsconfig.json` controls how strict the checker is. `strict: true` enables all strictness flags - the right default for new projects.
Where you'll actually use it
- Frontend frameworks (React, Vue, Svelte all support TS)
- Backend Node.js APIs (most modern Express/Fastify projects use TS)
- Library development (TypeScript types are the modern documentation)
- Large codebases where refactoring confidence matters
How it compares to alternatives
TS vs JS: TS catches bugs JS doesn't. TS vs Flow: Flow (Facebook's type checker) lost the type war - everyone uses TS now. TS vs JSDoc: JSDoc gives you types in plain JS - useful for libraries that don't want a build step.
Things that will trip you up
- Types are erased at runtime - `if (typeof x === 'MyClass')` doesn't work; use `instanceof` or runtime validators
- `any` defeats the type system entirely - use `unknown` for genuine 'unknown' values, not `any`
- Triple-slash directives (`///`) are TypeScript-specific imports - prefer ES module imports