TypeScript Compiler (Deprecated `tsc` package)
The `tsc` npm package is a **deprecated** placeholder that offered an older, unsupported release of the TypeScript compiler. Users seeking the TypeScript compiler's command-line interface (`tsc`) should install the official `typescript` npm package instead. The current stable version of the `typescript` package is 6.0.3, released recently (as of April 2026). TypeScript generally follows a quarterly release cadence for major versions, with monthly patch updates to address bugs and regressions. Key differentiators of the `typescript` package include its comprehensive static type-checking capabilities, support for modern ECMAScript features, and rich tooling integration. It transpile TypeScript code into various JavaScript targets, ensuring broad compatibility across browsers and Node.js environments.
Common errors
-
'tsc' is not recognized as an internal or external command, operable program or batch file.
cause The `tsc` command-line tool is not found in your system's PATH. This usually happens if `typescript` is installed locally but not globally, or if `npm`'s bin directory isn't in PATH.fixIf `typescript` is installed locally (`npm install -D typescript`), use `npx tsc` to execute the local version. If you intend to use it globally, install it via `npm install -g typescript`. -
error TSxxxx: <Some error related to an old TypeScript feature>
cause You are using an outdated version of the TypeScript compiler, possibly from the deprecated `tsc` package or an older global `typescript` installation.fixEnsure you are using the latest `typescript` package. Run `npm uninstall tsc && npm install -D typescript` in your project. If you have a global installation, run `npm update -g typescript`.
Warnings
- breaking The `tsc` npm package is officially deprecated and should not be used. It contains an outdated version of the TypeScript compiler and may lack critical features, bug fixes, or security patches present in the official `typescript` package.
- gotcha Attempting to use `tsc` directly after installing the deprecated `tsc` package will result in an outdated compiler version. This can lead to unexpected syntax errors, missing type definitions, or incompatibilities with modern TypeScript language features or libraries.
Install
-
npm install tsc -
yarn add tsc -
pnpm add tsc
Imports
- Programmatic usage of TypeScript compiler
import { tsc } from 'tsc'; // The 'tsc' package does not expose programmatic APIs.import ts from 'typescript'; const program = ts.createProgram(['./src/index.ts'], { target: ts.ScriptTarget.ES2020, module: ts.ModuleKind.CommonJS, }); // ... further programmatic compilation steps
Quickstart
/*
This quickstart demonstrates how to set up and use the actual TypeScript compiler (tsc)
by installing the officially supported 'typescript' npm package.
*/
// 1. Initialize a new Node.js project
// npm init -y
// 2. Install the official TypeScript compiler as a development dependency
// npm install --save-dev typescript
// 3. Initialize a tsconfig.json file for your project (optional, but recommended)
// npx tsc --init
// 4. Create a TypeScript file (e.g., src/index.ts)
// (You would typically create this file manually or through your IDE)
// src/index.ts
interface User {
id: number;
name: string;
email?: string;
}
function greetUser(user: User): string {
return `Hello, ${user.name} (ID: ${user.id})!`;
}
const newUser: User = {
id: 1,
name: 'Alice',
email: 'alice@example.com',
};
console.log(greetUser(newUser));
// 5. Compile your TypeScript code to JavaScript
// npx tsc
// This will create a 'dist' folder (or your configured outDir) with index.js
// You can then run the compiled JavaScript:
// node dist/index.js
// Output in console: Hello, Alice (ID: 1)!