Beyond one file
Real projects have many files, use npm packages, and run a build step. Here's how TypeScript fits in: modules share types, declaration files describe JavaScript libraries, and tsconfig.json sets the rules.
Sharing types between files
// types.ts
export interface Lesson {
id: string;
title: string;
}
// lessons.ts
import type { Lesson } from "./types";
export const lessons: Lesson[] = [{ id: "t01", title: "Why TypeScript?" }];- Declaration files (.d.ts) hold only types. They describe JavaScript code — like the browser itself (lib.dom.d.ts, which powered the last lesson) or npm packages.
- Many packages include their types. For others, install @types/<name> (from the DefinitelyTyped project).
- tsconfig.json configures the compiler. Turn on "strict": true — it's what you've used throughout this course.
- Build tools (Vite, Next.js, esbuild) remove types quickly; tsc --noEmit does the full type check, often in CI.