Let’s start from zero — you’ll go from installing TypeScript to running your first real TypeScript program.
We’ll cover everything step-by-step 💡
TypeScript runs on top of Node.js, so you need Node first.
👉 Download Node.js: Go to https://nodejs.org and install the LTS version (Long-Term Support).
Once installed, check:
node -v
npm -vIf you see version numbers, you’re good!
TypeScript is distributed as an npm package.
You can install it globally (available everywhere) or locally (per project).
npm install -g typescriptThen check:
tsc -vIf you see something like Version 5.x.x, TypeScript is installed 🎉
Make a new directory and open it:
mkdir ts-tutorial
cd ts-tutorialInitialize it as an npm project:
npm init -yThat creates a package.json file.
TypeScript uses a config file called tsconfig.json.
Generate one automatically:
tsc --initThis creates a file with many options. For now, open it and make sure these lines are set (you can edit it manually):
{
"compilerOptions": {
"target": "ES6",
"module": "CommonJS",
"rootDir": "./src",
"outDir": "./dist",
"strict": true
}
}📘 Explanation:
target: version of JavaScript to compile to.module: how imports/exports work.rootDir: where your TypeScript source files live.outDir: where compiled JS files go.strict: enables strict type-checking (recommended!).
Make a new folder and file:
mkdir src
cd srcCreate hello.ts:
// hello.ts
function greet(name: string): string {
return `Hello, ${name}!`;
}
console.log(greet("TypeScript"));Go back to the project root:
cd ..Then compile your code:
tscThis will:
- Read your
tsconfig.json - Convert everything from
/src→/dist - Produce a new file:
dist/hello.js
Now run the compiled JS with Node.js:
node dist/hello.js✅ Output:
Hello, TypeScript!
If you don’t want to compile every time, install ts-node:
npm install -g ts-nodeThen run TypeScript files directly:
ts-node src/hello.tsIt runs without manual compilation.
Now that you can run TypeScript, learn these next:
| Concept | Description |
|---|---|
| Types | string, number, boolean, any, unknown, never |
| Interfaces & Types | Define shapes of objects |
| Functions | Type parameters and return types |
| Classes | Object-oriented programming in TS |
| Generics | Reusable, type-safe functions/classes |
| Modules | import / export syntax |
| Enums | Named constant values |
| Union & Intersection types | Combine multiple type possibilities |