TypeScript Tutorial · TypeScript Basics · Lesson 2 of 25

TypeScript Get Started

Install TypeScript, compile with tsc and configure tsconfig.json.

Install

TypeScript is an npm package. Install it in your project:

npm install --save-dev typescript
npx tsc --version
npx tsc --init          # creates tsconfig.json

Compile and run

npx tsc                 # type-checks and writes .js files
node dist/index.js

To run .ts files directly during development, use tsx (npx tsx index.ts), or Node.js 22+'s built-in type stripping (node index.ts). Frameworks like Vite and Next.js compile TypeScript for you.

tsconfig.json essentials

{
  "compilerOptions": {
    "target": "ES2022",
    "module": "NodeNext",
    "strict": true,
    "outDir": "dist",
    "noUncheckedIndexedAccess": true
  },
  "include": ["src"]
}

Always enable strict — it turns on the checks that make TypeScript worthwhile, including strict null checking.

Example 1Try it yourself
const message: string = "TypeScript is set up!";
const year: number = 2026;
console.log(`${message} (${year})`);

Output

TypeScript is set up! (2026)

Test yourself

Which compiler option enables TypeScript's strictest checks?

  1. "checkAll": true
  2. "strict": true
  3. "safe": true
  4. "noAny": true
Show answer

Answer: "strict": true