Lesson

TypeScript Getting Started

10 min reading
Free Course

TypeScript Getting Started: Installing tsc and Running .ts Files

Getting started with TypeScript requires Node.js and npm. You install the typescript compiler locally inside your project as a dev dependency, generate a tsconfig.json file, and compile .ts files to JavaScript.

Keeping typescript inside each project's package.json ensures every teammate and CI server compiles with the exact same compiler version.

Step-by-Step Local Project Setup

Run these commands inside a new project folder to install TypeScript and create a default configuration file.

npm init -y
npm install -D typescript
npx tsc --init

Next, save a small script in src/greet.ts and compile it with npx tsc:

const developerName: string = "Karim";
const lessonsDone: number = 3;

console.log(`${developerName} completed ${lessonsDone} TypeScript lessons.`);

Run the compiler and execute the generated JavaScript file:

npx tsc
node dist/greet.js

Faster Execution During Development

During daily backend or script development, tools like tsx (npx tsx src/greet.ts) or Node.js 22.6+ (node --experimental-strip-types / native in 23.6+) run .ts files in one step without managing intermediate .js files manually.

Common Mistakes to Avoid

  • Installing typescript only globally: Global installs drift across machines; always list typescript in project devDependencies.
  • Running node file.ts on older Node versions: Node 20 and earlier cannot parse : string annotations and throw SyntaxError.
  • Editing compiled .js output instead of .ts: Changes inside dist/ get overwritten on the next tsc build.

Frequently Asked Questions

What does npx tsc --noEmit do?

It runs the full type checker across your project without writing .js files to disk—ideal for CI checks and projects bundled by Vite or Next.js.

How do I enable watch mode while coding?

Run npx tsc --watch (or npx tsc -w) so TypeScript recompiles changed files automatically whenever you save.

Where should compiled JavaScript files live?

Set "rootDir": "./src" and "outDir": "./dist" in tsconfig.json, and add dist/ to .gitignore.

Save Your Progress

Unlock Your
Full Potential.

Sign in to track your learning journey, earn industry-recognized certificates, and join our elite developer community.

Quick Access With

Enterprise-Grade Security Protocol

Try it Yourself

Experiment with the code from this lesson in our interactive playground.

Open Playground
TypeScript Topic Hub

Stuck on this lesson?

Join our community of senior developers.

Ask in Forum