How to Install TypeScript
What you’ll build or solve
You’ll install TypeScript globally or locally in a project. By the end, the TypeScript compiler will be available from your terminal and ready to use.
When this approach works best
This method works best when:
Learn TypeScript on Mimo
- You want to write and compile TypeScript locally on your machine.
- You’re starting a new project that requires TypeScript.
- You’re following a course that uses the
tsccommand.
Skip this if you’re using an online editor like StackBlitz or CodeSandbox that already includes TypeScript.
Prerequisites
- Node.js installed
- Access to a terminal
Check that Node.js is installed:
Bash
node -v
Check that npm is available:
Bash
npm -v
Both commands should print a version number.
Step-by-step instructions
Step 1: Choose your installation method
Pick one of the options below.
Option A: Global installation (quick start)
This installs TypeScript system-wide.
Bash
npm install -g typescript
Verify it:
Bash
tsc -v
You should see something like:
Version 5.x.x
This allows you to run tsc from any folder.
Option B: Local installation (recommended for projects)
Use this if you’re working inside a specific project.
Create a project folder and move into it:
Bash
mkdir my-project
cd my-project
Initialize the project:
Bash
npm init -y
Install TypeScript as a development dependency:
Bash
npm install --save-dev typescript
Verify it:
Bash
npx tsc -v
npx runs the local version installed in your project.
Option C: Alternative package managers
If you use Yarn:
Bash
yarn add --dev typescript
If you use pnpm:
Bash
pnpm add -D typescript
Then verify with:
Bash
npx tsc -v
What to look for
tsc -vworks for global installsnpx tsc -vworks for local installs- If you see “command not found,” restart your terminal and try again
Installation is complete once the version command works.
Step 2: Verify the installation works
Create a test file called index.ts:
let message: string = "Hello!";
console.log(message);
Now compile it.
If you installed globally:
Bash
tsc index.ts
If you installed locally:
Bash
npx tsc index.ts
This creates:
index.js
Run it with Node:
Bash
node index.js
If you see:
Hello!
TypeScript is installed correctly.
Examples you can copy
These examples help confirm your setup works.
Example 1: Simple number
let age: number = 30;
console.log(age);
Compile:
Bash
tsc index.ts
or
Bash
npx tsc index.ts
Example 2: Function with types
function multiply(a: number, b: number): number {
return a * b;
}
console.log(multiply(4, 5));
Compile and run:
Bash
tsc index.ts
node index.js
Example 3: Intentional type error
let score: number = "100";
Compile:
Bash
tsc index.ts
You should see a type error in the terminal. That confirms TypeScript is checking types correctly.
Common mistakes and how to fix them
Mistake 1: Running a .ts file directly with Node
What someone might do:
Bash
node index.ts
Why it breaks:
Node does not understand TypeScript syntax.
Correct approach:
Bash
tsc index.ts
node index.js
Or use npx tsc for local installs.
Mistake 2: tsc is not recognized
What someone might see:
tsc: command not found
Why it happens:
TypeScript is not installed globally, or your terminal session has not refreshed.
Fix:
- Restart the terminal
Or use:
Bash
npx tsc -v
Mistake 3: Skipping npm init for local install
What someone might do:
Bash
npm install --save-dev typescript
Without creating a project first.
Why it causes issues:
No package.json exists, so the dependency is not tracked properly.
Fix:
Bash
npm init -y
npm install --save-dev typescript
Troubleshooting
If tsc -v fails but installation succeeded, restart your terminal.
If npx tsc fails, confirm you’re inside the correct project folder.
If permission errors appear during global install, try running your terminal as administrator, or use local installation instead.
If Node reports version conflicts, update to a recent LTS version of Node.js.
Quick recap
- Install Node.js first.
- Install TypeScript globally with
npm install -g typescript, or locally withnpm install --save-dev typescript. - Verify using
tsc -vornpx tsc -v. - Compile a small test file to confirm everything works.
- Run the compiled JavaScript with Node.
Join 35M+ people learning for free on Mimo
4.8 out of 5 across 1M+ reviews
Check us out on Apple AppStore, Google Play Store, and Trustpilot