noEmitOnError
is a compiler option in tsconfig.json
file. If the value of this property is set to true
, TypeScript will not generate output JavaScript file if there is any TypeScript error.
{
"compilerOptions": {
//...
"noEmitOnError": true
}
}
Here is a TypeScript file that has an error:
const input = document.getElementById("age");
const value = input.value;
Here, TypeScript throws an error in second line because input
can have a null
value if the element does not exist. That will be an issue when we try to access value
of null
.
By default when we compile, even though TypeScript shows error in console, it generates output JavaScript with below code:
"use strict";
const input = document.getElementById("age");
const value = input.value;
If we set noEmitOnError
to true
, the out JavaScript is not generated.