TYPESCRIPT / LESSON 07
Setting Up a TypeScript Project.
Configuring tsconfig.json and setting up a TypeScript project from scratch

Loading the lesson…
Loading activities…
TYPESCRIPT / LESSON 07
Configuring tsconfig.json and setting up a TypeScript project from scratch

Loading the lesson…
Loading activities…
You've learned the TypeScript language. Cool. Now let's actually set up a project.
Think of it like setting up a workshop. You've got the skills (your TypeScript knowledge), but you still need a workbench (the project configuration) and the right tools on the wall (compiler options) before you can build a darn thing.
Setting up a TypeScript project only takes a few steps.
Make a new folder and initialize it with npm.
That gives you a package.json file, which keeps track of your project's dependencies.
Add TypeScript as a development dependency.
That installs the TypeScript compiler (tsc) right inside your project, plus @types/node, which teaches TypeScript about Node.js stuff like console and process. (Newer TypeScript versions don't load those type packages automatically anymore, so we'll point at it in the config below.)
Generate a TypeScript configuration file.
That creates a starter tsconfig.json file. What's inside depends on your TypeScript version... older versions dump in every option with most of them commented out, and newer ones give you a shorter starter with a few lines you're meant to uncomment. Either way, don't panic. We're about to swap in our own version anyway.
Make a src folder for your first TypeScript file.
Then create src/index.ts and put some TypeScript in it.
Compile your TypeScript into JavaScript, then run it. (This step expects your compiled files to land in a dist folder, which the config in the next section sets up. A fresh starter config might drop them next to your source files instead.)
The tsconfig.json file is the control panel for how TypeScript compiles your code. Here's a beginner-friendly setup.
Let's break down what each of those does.
ES2022 is a safe modern pick for current Node.js. Older targets rewrite modern syntax so older runtimes can handle it.nodenext for modern Node.js projects, esnext or preserve when a bundler like Vite handles your code."node" in here even console.log gets flagged as an error (fun way to start your first file, right?).Strict mode flips on all the strict type-checking options in one shot. TypeScript 6 and up turns it on by default, but write it in anyway so nobody reading your config has to guess. If you only remember ONE option from this lesson, make it this one, because it catches the most bugs. Here's some of what it turns on.
any)null and undefinedAdd a few handy scripts to your package.json.
Most modern frameworks come with TypeScript support baked right in.
Next.js sets up TypeScript for you with a sensible tsconfig.json. Your components use the .tsx extension.
Vite gives you fast TypeScript compilation and hot module reloading, so the page updates the moment you save.
If you want to run TypeScript directly and skip the compile step, newer Node.js (22.18 and up) can do it with no extra packages.
Node just strips the types out and runs what's left. It does NOT check your types, so keep npx tsc --noEmit around to catch mistakes.
| Extension | Used For |
|---|---|
.ts | Regular TypeScript files |
.tsx | TypeScript files with JSX (React components) |
.d.ts | Type declaration files (types only, no runtime code) |
.js | Compiled JavaScript output |
.js.map | Source maps (for debugging) |
Some JavaScript libraries don't come with TypeScript types. No biggie, you can install the type declarations separately.
The @types/ packages hand TypeScript the type info for popular JavaScript libraries.
Here's what a typical TypeScript project looks like.
npm init and npm install typescripttsconfig.json controls how TypeScript compiles your codestrict: true for the most type safetyoutDir and rootDir to keep source and compiled output apart@types/ packages for libraries that don't ship their own types.ts for regular files and .tsx for React component filesYou've got a real project set up now, with a config that catches your mistakes. In the last lesson of this module we bring React into it... typing component props, state and events.