I want to debug my project and I find small problem with creating instance of class. I try to describe it on simple example.
//this is saved in file Engine.ts
module Car {
export class Engine {
name: string;
constructor(name: string) {
this.name = name;
}
getName(): string{
return this.name;
}
}
}
This class describes simple engine with his name. Now I want to create Engine in some vehicle:
///<reference path="Engine.ts"/>
//this is saved in file app.ts
module Car {
export class Vehicle {
name: string;
constructor(name: string) {
this.name = name;
}
buildCar() : string {
var engine = new Engine("Volkswagen 1.9TDI");
return "Name of the vehicle is " + this.name + " and has engine " + engine.getName();
}
}
}
window.onload = () => {
var car = new Car.Vehicle("Skoda Rapid");
alert(car.buildCar);
}
The problem is with creating instance of class Engine. The browser console returns error that Car.Engine is not a constructor. How can I fix this problem? I have more difficult project and this describes only main principle of problem. In my project I must create instance of some class in function of other class.