TypeScript Reference ยท tsconfig: Language, Modules and Emit Options
TypeScript noEmitOnError option
Reference for noEmitOnError: stop tsc from writing JavaScript when any type error exists, why the default emits anyway, and how it affects watch mode.
By default tsc is permissive: it reports type errors but still writes JavaScript, because the types are erased and the code may well work. noEmitOnError reverses that. If the compiler finds any error, it writes no output files at all.
This matters when output goes straight to a deploy step. With the default, a build can "fail" yet leave fresh .js files in dist, and a script that ignores the exit code ships them. The option guarantees that what is in dist passed the type check. This site's runner uses it, so a type error stops the run.
{ "compilerOptions": { "noEmitOnError": true } }
Try it
Because this runner compiles with --noEmitOnError, the second example never runs: the compiler prints its error and stops.
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or readFileSync(0)), it gets the next line from this box.
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or readFileSync(0)), it gets the next line from this box.
Syntax
{ "compilerOptions": { "noEmitOnError": true } }
| Name | Description |
|---|---|
noEmitOnError |
true: no files are written if there is any error. false (default): files are written even with errors. |
Usage notes
- The second example fails on purpose and prints
Type 'string' is not assignable to type 'number'with the line and column. - It considers all errors in the program, including syntax errors and errors in unrelated files; one broken file blocks everything.
- In
--watchmode, a failing change leaves the last good output untouched instead of overwriting it with possibly broken code. noEmitis different: it never writes, even for a clean program.- With
declarationon,.d.tsfiles are also skipped when errors exist. - Incremental builds (
incremental) keep state about the failed run, so fixing the error and recompiling is fast. - Most teams set it in the build config, not in the editor-facing config.