TypeScript Compiler Options

--clean — TypeScript build command

Deletes compiler-known outputs for selected projects and referenced dependencies. Use dry clean first in unfamiliar workspaces; it is not a general directory deletion or a guarantee of removing obsolete artifacts. The example operates only on isolated generated outputs. Baseline: TypeScript 5.8.3. Default: false. Example: create the labeled files in an isolated project and run the commands in order. See companion fixtures for comparison cases and expected results. Generated JavaScript, declarations and build info are removed; original sources remain.

Formal Syntax & Structure

typescript syntaxtypescript
tsc --build --clean

Parameters & Attributes

NameTypeDescription
cleanbooleanBuild-mode flag; default: false.

Working Example

Example Snippettypescript
// File: tsconfig.json (omit this label){  "files": [],  "references": [    {      "path": "./app"    },    {      "path": "./lib"    }  ]}// File: lib/tsconfig.json (omit this label){  "compilerOptions": {    "target": "ES2022",    "module": "CommonJS",    "strict": true,    "types": [],    "composite": true,    "rootDir": "src",    "outDir": "dist",    "tsBuildInfoFile": "dist/lib.tsbuildinfo"  },  "include": [    "src/**/*.ts"  ]}// File: lib/src/index.ts (omit this label)export const value: number = 7;// File: app/tsconfig.json (omit this label){  "compilerOptions": {    "target": "ES2022",    "module": "CommonJS",    "strict": true,    "types": [],    "composite": true,    "rootDir": "src",    "outDir": "dist",    "tsBuildInfoFile": "dist/app.tsbuildinfo"  },  "include": [    "src/**/*.ts"  ],  "references": [    {      "path": "../lib"    }  ]}// File: app/src/index.ts (omit this label)import { value } from "../../lib/dist/index";console.log(value + 1);
// Run these commands in order in an isolated project:// tsc --build --pretty false// tsc --build --clean --pretty false
TypeScript Reference