If we compile TypeScript classes they will become JavaScript functions, similarly if we compile Interfaces of TypeScript what output will be generated in compiled .js file?

 Posted by Saurabhsingh1408 on 3/28/2018 | Category: TypeScript Interview questions | Views: 1570 | Points: 40
Answer:

Interfaces will be used by typscript at compile time, after that they will be removed and they will not be the part of final javascript output.

Eg :
interface IVehicle
{
engine:string;
fuel:string;
}

class Car implements IVehicle
{
constructor (public engine: string, public fuel: string) {
}
}

Above typescript code will compile to following javascript code :
var Car = /** @class */ (function () {
function Car(engine, fuel) {
this.engine = engine;
this.fuel = fuel;
}
return Car;
}());


Asked In: Euromonitor Bangalore Interview | Alert Moderator 

Comments or Responses

Login to post response

More Interview Questions by Saurabhsingh1408