Interactive development
A developer edits TypeScript files and wants automatic recompilation and diagnostics.
TypeScript · Command
tsc --watch keeps the TypeScript compiler running and monitors input files for changes. Configure its file and directory-watching behavior with watch-related compiler options or watchOptions in tsconfig.json.
Run tsc --watch to keep the TypeScript compiler active while it monitors the project’s input files. When changes are detected, it recompiles and reports diagnostics; watch behavior can be adjusted through watchOptions in tsconfig.json or related watch flags.
tsc --watch [options]| Name | Type | Description |
|---|---|---|
--watch | boolean | Enables watch mode so the compiler monitors input files. |
A continuously running compiler process that watches input files and recompiles when changes are detected.
watchOptions section of tsconfig.json.tsc --watch --project tsconfig.jsonRuns the TypeScript compiler in watch mode for the project described by tsconfig.json; keep the process running and edit an input file to trigger recompilation.
A developer edits TypeScript files and wants automatic recompilation and diagnostics.
A project needs compiler output to stay current during a long-running local process.
A large repository needs platform-specific watcher strategies or exclusions.
tsc --watch do?--watch keeps the compiler running and watches input files for changes. The compiler then responds to detected changes instead of requiring a separate command for every edit.
Follow-up: How can watch behavior be configured? Use the watchOptions section in tsconfig.json, or the corresponding watch-related compiler options.
The implementation relies on Node’s fs.watch and fs.watchFile. Native file-system events can be efficient, while polling is generally more reliable but uses CPU cycles.
Follow-up: What is the default file-watching strategy? The documentation identifies useFsEvents as the default strategy in the watch configuration options.
watchOptions can control how files and directories are watched, including file strategy, directory strategy, fallback polling, and whether directory watching is synchronous. This lets a project adapt watch behavior to its platform and workload.
Follow-up: When is a fallback useful? It can provide an alternative when native watchers cannot be created or when the platform limits active watches.
watchOptionswatchFilewatchDirectoryfallbackPollingsynchronousWatchDirectorypreserveWatchOutputexcludeDirectoriesexcludeFiles