Module 04 — TypeScript Fundamentals
Why TypeScript?
TypeScript is a superset of JavaScript that adds static types. It compiles to plain JavaScript but catches an entire class of bugs before your code ever runs.
// JavaScript — no error until runtime
function getUser(id) {
return fetch(`/api/users/${id}`).then(r => r.json());
}
getUser(undefined); // silent bug
// TypeScript — caught at compile time
function getUser(id: number): Promise<User> {
return fetch(`/api/users/${id}`).then(r => r.json());
}
getUser(undefined); // Error: Argument of type 'undefined' is not assignable to 'number'
Industry Adoption
TypeScript is now the default for serious frontend and backend projects:
- React — all official docs use TypeScript
- Next.js — TypeScript by default
- NestJS — written in TypeScript, requires it
- Prisma — generates TypeScript types from your schema
- tRPC — only works with TypeScript
Learning Objectives
By the end of this module you can:
- Annotate variables, function parameters, and return types
- Define object shapes with
interfaceandtype - Write reusable logic with generics
- Use built-in utility types (
Partial,Required,Pick,Omit, etc.) - Configure
tsconfig.jsonfor a real project
Module Lessons
Challenge
Migrate the Module 03 Payroll Tracker from JavaScript to TypeScript:
- Add types to all functions and variables
- Create
EmployeeandPayrollStateinterfaces - Use generic utility types where appropriate