A
A
Alexey Gagarin2016-01-23 00:38:41
JavaScript
Alexey Gagarin, 2016-01-23 00:38:41

Why does is not a constructor appear?

Hello! Guys, I'm trying to write a simple game in TypeScript and ... I'm stuck at the very beginning.
There is something like this code (3 different files):

window.onload = () => {
    var g: Tower.Weapon;
    g = new Tower.MachineGun();

};

module Tower {
    export class Weapon {
    }
}

module Tower {
    export class MachineGun extends Weapon {

    }
}

In general, the simplest inheritance. The MachineGun class extends the Weapon class... And an instance of this class is created in App.ts.
Well... the code is not executed. TypeError appears in the browser console: Tower.MachineGun is not a constructor.
Of course, I'm not very well versed in JS ... in general, tell me if anyone knows ...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Gagarin, 2016-01-23
@Alexey_Gagarin

Seems. figured it out myself. In the project settings, I checked the box to collect all TS files into one JS. At the same time, for some reason, the correct order of the scripts in the file is not always observed ... The MachineGun declaration appears before the Weapon. hence the error... Added to MachineGun.ts /// and it seems to work...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question