Skip to content

tsconfig.json and Strict Mode Explained: Set Up a TypeScript Project and Run tsc

NeedMyTools Academy

Sign in free to read the full lesson

Sign in or create a free account

Free forever. No card, no paywall.

Every example so far ran with one fixed set of rules: the compiler in strict mode, checking a single script. Real projects decide those rules themselves in a file called tsconfig.json, and the most important line in it is "strict": true. This lesson explains what that line actually switches on, by showing the errors each part catches, and how the compiler fits next to the tools you will meet in practice, where the code often runs without being type checked at all unless you ask. It ends with the escape hatches TypeScript offers, which ones are honest, and how to move an existing JavaScript project over without stopping work.

Quick answer

Install TypeScript in the project with npm install --save-dev typescript and create a config with npx tsc --init. Keep "strict": true: it turns on noImplicitAny, strictNullChecks, useUnknownInCatchVariables, strictPropertyInitialization and the other strict checks together. Run npx tsc --noEmit to type check without writing files, because Vite, Next.js, esbuild and Node.js type stripping run TypeScript without checking it. Consider noUncheckedIndexedAccess for safer array and record lookups. Prefer @ts-expect-error to @ts-ignore, and fix the cause rather than silencing it. Move JavaScript over file by file with allowJs.

35 min read and practice · Content checked on 17 November 2026

In this lesson you will

  • Install TypeScript, create tsconfig.json and run tsc
  • Explain what strict mode switches on and why to keep it
  • Type check in projects built with Vite, Next.js or Node.js
  • Choose honest escape hatches and migrate JavaScript gradually

From playground to project: tsc and tsconfig.json

In a project folder with Node.js installed, run npm install --save-dev typescript. That gives you the compiler, tsc, pinned to a version in package.json so everyone on the team uses the same one. Then npx tsc --init writes a starter tsconfig.json; recent versions write a short file with modern defaults and strict mode on. Its main parts are compilerOptions, which hold the rules, and include, which says which files belong to the project, for example ["src"]. Running npx tsc checks every included file and writes JavaScript, and npx tsc --watch keeps doing it as you save.

A few options matter early. target is the JavaScript version to output, such as "ES2022". module decides how imports are written, and modern projects use "ESNext" or "NodeNext". outDir puts the output in a separate folder, such as "dist". lib lists the built-in types available; include "DOM" for browser code. noEmit tells tsc to check only and write nothing, which is what you want when another tool builds the code. skipLibCheck skips checking the type files of installed packages, which saves time and is set in almost every project.

Try it: What "strict": true catches
Code
ResultUpdates as you type
Console
  1. Console messages, errors, form data and clicked links appear here.

The compiler reports four errors, one per strict check named in the comments. Then the JavaScript runs anyway: the cart total prints undefined, and the last line crashes because there is no #qty element. Each of those run-time surprises was one of the reported errors.

Sign in free to read the full lesson

You are reading the free preview. Create a free account (it takes one minute, no password) to unlock the rest of this lesson and track your progress.

Unlocks after sign-in:

  • 3 more sections with live code examples
  • Common mistakes to avoid
  • Hands-on coding exercise with automatic checks
  • Practice quiz and the graded lesson test
Sign in or create a free account

Free forever. No card, no paywall.

Questions people ask

What does "strict": true do in tsconfig.json?

It switches on a family of checks together, including noImplicitAny, strictNullChecks, strictFunctionTypes, strictPropertyInitialization and useUnknownInCatchVariables. New versions of TypeScript may add checks to the family, so upgrading can reveal new errors; that is intended.

Can Node.js run TypeScript files directly?

Yes. Since Node.js 22.18 and 23.6, node file.ts runs a TypeScript file by stripping its types. It does not type check, and syntax that needs real code generation, such as enum, is not supported by default. Run tsc --noEmit separately to check.

Should a beginner turn strict mode off?

No. Strict mode catches the bugs beginners make most, such as a value that may be null. Turning it off removes the warnings, not the bugs. It is only reasonable as a temporary step when moving a large old JavaScript project over.

What is the difference between @ts-ignore and @ts-expect-error?

Both hide the type error on the next line. @ts-ignore stays silent even if the line has no error, while @ts-expect-error reports itself as unused once the error is gone, so stale suppressions do not pile up.

What are @types packages in npm?

They hold type definitions for libraries written in JavaScript, maintained by the community in the DefinitelyTyped project. For example, @types/node describes Node.js. Install them as dev dependencies; packages that ship their own types do not need one.

Sources

Facts in this lesson were checked against these official pages on 17 November 2026.

Code examples stay in English and run in a sandbox on your device. If you spot a mistake, tell us through the contact page.