sumi sumi - 3 months ago 17
Javascript Question

JavaScript file should not get generated if Typescript file has any error

Consider below Typescript code

class formal
{
private startString: String = "";
constructor(startString:String)
{
this.startString = startString;
}

public sayHello = function() :Number {
alert(this.startString);
}

}

var myIntro = new formal("hello world");
myIntro.sayHello();


Currently It has following error
"A function whose declared type is neither 'void' nor 'any' must return a value.
An object that represents a number of any kind. All JavaScript numbers are 64-bit floating-point numbers.
"

But after running tsc command it is generating corresponding js file.
What I need is that it should not generate corresponding JS file until all the errors are resolved of typescript file.

Is there any way to achieve this?

Answer

add --noEmitOnError to your compiler.

It would properly look something like this: tsc myFile.ts -w --noEmitOnError

Comments