TypeScript is an npm package. It needs Node.js to be installed.

Install it as a dev dependency, so every developer and every CI run uses the same version:

npm install -D typescript

Run the project's compiler through your package manager:

npx tsc --version

Globally

A global install gives you a tsc command everywhere, which is handy for quick experiments:

npm install -g typescript
A global tsc can be a different version from the one your project uses. Inside a project, prefer npx tsc.

Your First Program

  1. Create hello.ts:
    hello.ts
    function greet(name: string): string {
      return `Hello, ${name}!`;
    }
    
    console.log(greet("Pirate Dev"));
    
  2. Compile it:
    npx tsc hello.ts
    

    This writes hello.js next to it.
  3. Run the JavaScript:
    node hello.js
    

Now change the call to greet(42) and compile again. tsc reports the mistake:

hello.ts:5:19 - error TS2345: Argument of type 'number' is not assignable to parameter of type 'string'.
tsc still writes hello.js even when there are type errors, unless noEmitOnError is set. See tsconfig.json.

Running .ts Files Directly

Recent Node.js versions (22.18+ and 23.6+) can run a .ts file directly with node hello.ts. Node only strips the types; it does not type-check, and syntax that needs code generation (like enum or parameter properties) isn't supported this way. Keep running tsc (often tsc --noEmit) to catch type errors.