TypeScript
JavaScript with an added static type system, compiled down to plain JS.
CurrentintermediateFull course available
Overview
TypeScript is a superset of JavaScript that adds static types, catching a category of bugs (wrong argument types, typos in property names) at compile time instead of runtime. It compiles to plain JavaScript, so it runs anywhere JavaScript does.
- What it is
- JavaScript plus an optional, gradually-adoptable static type system.
- Why it's used
- Types catch mistakes before code runs and make large codebases easier to navigate and refactor safely.
- Where it fits
- After JavaScript fundamentals -- TypeScript adds types on top, it doesn't replace JS concepts.
Core concepts
- Type annotations
- Interfaces and type aliases
- Generics
- Type inference
- Compiling to JavaScript
Example
The type annotations (: number) tell the compiler what's allowed -- passing a string where a number is expected fails at compile time, not in production.
function add(a: number, b: number): number {
return a + b;
}
add(2, "3"); // compile error: caught before runningCommon use cases
- Large frontend codebases
- Any Node.js backend that benefits from compile-time safety
- Public library APIs
Project ideas
- Add type annotations to an existing small JavaScript project and fix the errors TypeScript surfaces