TypeScript Compiler Options
watch — TypeScript watch configuration
Keeps the compiler process active, observes changes and recompiles the affected program. A watch process is not a production server or a substitute for a clean CI check. The initial valid file compiles and the subsequent edit produces TS2322. Baseline: TypeScript 5.8.3. Default: false. Create the labeled files in an isolated project; omit file labels. Stop the ongoing watcher with Ctrl+C.
Formal Syntax & Structure
typescript syntaxtypescript
tsc --watchParameters & Attributes
| Name | Type | Description |
|---|---|---|
| watch | boolean | CLI switch; default: false. |
Working Example
Example Snippettypescript
// File: tsconfig.json (omit this label){ "compilerOptions": { "target": "ES2022", "module": "CommonJS", "strict": true, "types": [], "noEmit": true, "preserveWatchOutput": true }, "include": [ "src/**/*.ts" ]}// File: src/index.ts (omit this label)export const count: number = 1;
// Run in a temporary project:// tsc -p . --watch --pretty false// After initial compilation, apply the following file change; stop watch with Ctrl+C.// Replace or create: src/index.tsexport const count: number = "bad";