NestJSNest building blocksLesson 40 / 69

From JavaScript to TypeScript

Docs20 min

From JavaScript to TypeScript

TypeScript is JavaScript that knows what things are:

function addMinutes(total: number, mins: number): number {
  return total + mins;
}

interface Lesson { id: string; title: string; minutes: number }

Why bother on a server? Because a backend is a long chain of hands — request → DTO → service → database → response — and one wrong shape silently poisons everything downstream. Types make the shapes impossible to mix up, and the editor tells you before the user does.

The whole rest of this course is typed. npm run build failing is not an error; it is the compiler doing code review for free.

Exercise

Take your reading-list functions and add types to every parameter and return. Write an interface for a Book.