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.
Console
- 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
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.
- TypeScript: What is a tsconfig.json
- TSConfig reference: strict
- TSConfig reference: noUncheckedIndexedAccess
- TypeScript 5.8 release notes: erasableSyntaxOnly
- Node.js: Running TypeScript natively
- TypeScript Handbook: Migrating from JavaScript
Code examples stay in English and run in a sandbox on your device. If you spot a mistake, tell us through the contact page.