01 / 09
What TypeScript is, why it is used and type checking in a first project.
TypeScript is a language that adds a static type system on top of JavaScript. It contains all of JavaScript's features; every piece of working JavaScript is also valid TypeScript.1 That is why TypeScript is called a superset of JavaScript.
The difference is this: you write down which type a variable, a function parameter or an object has (or you let TypeScript work it out), and before the code runs, a type checker checks whether those types are consistent.2
This lesson covers what TypeScript is, how it is installed in a project and where the type checking happens. Writing the types themselves comes step by step in the lessons that follow.
JavaScript is dynamically typed: a variable's type is only known once the code runs. TypeScript gives you that information while you are writing. There are three concrete benefits:
Errors show up before you run anything. A value of the wrong type, a misspelled property, a function you forgot to call: all of them get a red line in the editor.2
The editor knows your code. Autocomplete shows which fields an object has and which parameters a function expects.
Changing things is safe. Rename a field and every file that uses it reports an error; nothing slips past you.
The industry went the same way. In the State of JS 2025 survey, 40% of respondents said they write TypeScript only (34% in 2024); missing static types is still named as JavaScript's biggest pain point.3
Think of a simple piece of JavaScript that works out a cart total. One of the prices arrived from the API as text:
const cart = [
{ name: "Wireless Headphones", price: 1299 },
{ name: "Phone Case", price: "249" },
];
const total = cart.reduce((sum, item) => sum + item.price, 0);
console.log(total); // "1299249" — string concatenation, not additionJavaScript raises nothing; it quietly produces the wrong answer. Write the same code in TypeScript, describing the shape of a cart item, and the error is caught before the code runs:
type CartItem = {
name: string;
price: number;
};
const cart: CartItem[] = [
{ name: "Wireless Headphones", price: 1299 },
{ name: "Phone Case", price: "249" },
// Error: Type 'string' is not assignable to type 'number'.
];Defining types with type is covered in detail in Interface, type and union.
Browsers and Node.js do not understand TypeScript types. Before the code runs the types are stripped, and what is left is plain JavaScript. As the Handbook puts it, type annotations never change the runtime behaviour of the program.2
// What you write
function formatPrice(price: number): string {
return `€${price}`;
}
// What runs (after the types are erased)
function formatPrice(price) {
return `€${price}`;
}Warning
TypeScript only checks the code you wrote. Data from fetch, the result of JSON.parse and form input all arrive at runtime and pass through no type check at all. Giving an API response the Product type does not guarantee the data really looks like that. Narrowing that kind of data safely is covered in Narrowing and type guards, and validating it with a schema in the Zod lesson on the Forms track.
The shortest way to try something without installing anything is the TypeScript Playground.4 You write code on the left, errors appear underlined straight away, and on the right you watch the JavaScript output with the types stripped. You can share what you wrote as a link, which is very handy when asking a question.
Paste the cart example above into the Playground and try hovering over the price: "249" line.
TypeScript files use the .ts extension. Any file that contains JSX has to be .tsx; the extension is what tells TypeScript there is JSX in the file.5
| File | Extension |
|---|---|
| Type definitions, helper functions, API calls | types.ts, format-price.ts |
| React components | ProductCard.tsx, App.tsx |
The easiest way to start a TypeScript project with React is Vite's react-ts template.6
$ pnpm create vite@latest my-store -- --template react-tsThe template comes with src/main.tsx and src/App.tsx ready, and three tsconfig files in the root (tsconfig.json, tsconfig.app.json, tsconfig.node.json). The build script in package.json is tsc -b && vite build: the type check runs first, and the build stops if there is an error.
Tip
As of October 2026 the create-vite 9.2 template installs the typescript package as ~6.0.2, while the latest release on npm is 7.0. The reason for the gap is in the TypeScript 7 section below.
The tsconfig files tell the compiler which files to check and under which rules; the detail is in tsconfig and strict mode.
TypeScript is an npm package, and it brings a compiler command called tsc.2 Install it as a development dependency:
$ pnpm add -D typescriptThen create a tsconfig.json:
$ pnpm dlx tsc --initIn TypeScript 7 this command produces a file with the recommended settings such as strict, noUncheckedIndexedAccess and verbatimModuleSyntax turned on. In a React project you also need the @types/react and @types/react-dom packages.5 After that you can start turning files into .ts / .tsx one at a time; the JavaScript files keep working.
This is the point newcomers to TypeScript skip most often. TypeScript does two separate jobs in a project, and different tools do them:
| Job | Who does it |
|---|---|
| Stripping the types and producing JavaScript | Vite (Oxc), Next.js (SWC), esbuild, Node.js |
| Checking whether the types are correct | tsc and the editor |
Vite only transforms .ts files and does no type checking; its documentation leaves that job to the editor and the build process.7 So the development server will happily run code with a type error in it. Next.js also compiles with SWC during development, while next build does type check by default and stops the build on an error.8
That is why you run the type check separately:
$ pnpm dlx tsc --noEmit--noEmit only checks, without producing JavaScript files. In the Vite template the right command is npx tsc -b.
Caution
The root tsconfig.json in the Vite template contains no files of its own ("files": []); it only references the other two. Running npx tsc --noEmit in the root therefore checks nothing and succeeds even when there are errors. Use npx tsc -b in Vite projects.
In practice you see type errors in three places: in the editor as you write, during the build, and in CI. The CI step is set up in tsconfig and strict mode.
From versions 22.18 and 23.6 on, Node.js can run .ts files with no extra tooling; the feature became stable in 24.12 and 25.2.9 Node replaces the type syntax with whitespace and runs the code, which is called type stripping.
$ node price.tsThe approach has two limits:9
There is no type checking. Badly typed code runs too; you still need tsc to check it.
Only erasable syntax is supported. enum, namespace with runtime code, and class parameter properties all need a transform, so they are not supported. .tsx files do not run either, and tsconfig.json is not read.
It is ideal for scripts and small tools. In a React application, Vite or Next.js does this job.
TypeScript 7, released on July 8, 2026, is the native version of the compiler, ported to the Go language. It is typically 8 to 12 times faster on a full build; installing it and the tsc command stay the same.10 strict is now on by default.
TypeScript 7 does not offer a JavaScript API yet. Tools that use TypeScript as a library (typescript-eslint, Vue and Svelte among them) work with 6.0 for now, and the @typescript/typescript6 package was published for that.10 That is why the Vite template still installs 6.0. Next.js, on the other hand, uses the project's own tsc command during next build, so it works with TypeScript 7 directly.8
If you are just starting out, the split barely affects you: code that compiles cleanly on 6.0 compiles the same way on 7.0.10
Write the CartItem type from the first example in the Playground, make price a string and read the error message.
Misspell a field name in the same code (item.prise) and look at what TypeScript suggests.
Create a react-ts project with npm create vite@latest, put a deliberate type error in App.tsx, and while npm run dev is running, find it with npx tsc -b.
Write a price.ts file and run it with node price.ts.
Official docs: the "The Basics" chapter of the TypeScript Handbook; static type checking, tsc and erased types.2
Book: the "TypeScript In The Development Pipeline" chapter of Matt Pocock's Total TypeScript Essentials, readable online.11
Book: Dan Vanderkam's Effective TypeScript (2nd edition, 2024, 83 items).12
Talk: Anders Hejlsberg's "A 10x faster TypeScript" on porting the compiler to Go (Microsoft Developer, 2025, 14 min).13
Practice: every example in this lesson runs in the TypeScript Playground.4
Sources
Existing JavaScript code also being TypeScript, and type inference.
Static type checking, installing `tsc`, "Erased Types" and the strict settings.
40% of respondents writing TypeScript only; missing static types as the biggest pain point.
Writing TypeScript in the browser, the output and a shareable link.
Files with JSX being `.tsx`, and adding `@types/react` to an existing project.
The `npm create vite@latest` command, the `--template` flag and the Node.js version requirement.
Vite only transforming, doing no type checking, and the `tsc --noEmit` recommendation.
Type checking during `next build`, `ignoreBuildErrors` and use with TypeScript 7.
The versions where type stripping is the default, the unsupported syntax and the absence of type checking.
The native compiler, the 8–12x speed-up, the new defaults and tool compatibility through `@typescript/typescript6`.
: — The browser not being able to run TypeScript, Vite not type checking, and `tsc --noEmit` in CI.
: — The 83-item book, and a blog of TypeScript writing.
About 14 minutes. The decision to go native with Go, and the first measurements.
Check the lesson's main ideas with three questions.
Your progress is stored only in this browser.
Last updated: November 3, 2026