I saw this question which is similar :
Cross referencing with extended classes in TypeScipt
though i couldnt figure out what was wrong still. My problem is that i have a class gameobject that i want to extend but as long as the sprite class that entends gameobject exists i get an error
module Game {
export class GameObject {
x = 0;
y = 0;
W = 0;
H = 0;
img = new Image();
scale = 0;
constructor(img, x, y, w, h, scale?) {
this.img = img;
this.x = x || 0;
this.y = y || 0;
this.W = w;
this.H = h;
this.scale = scale || 1;
}
update() {
}
render(context, x, y) {
context.drawImage(this.img, this.x, this.y, this.W, this.H, x, y, this.W * this.scale, this.H * this.scale);
}
}
}
.
module Game {
export class Sprite extends GameObject {
}
}
I get the following error:
Uncaught TypeError: Cannot read property 'prototype' of undefined
Uncaught TypeError: undefined is not a function
According to the post at the top, it seems like i have a circular dependency and it it calling the sprite class first for some reason?
Thanks in advance.
I found the error, apparently you cannot extend files normally when you are outputting the typescript code to one javascript file so you have to use ///reference like this:
///<reference path='gameobject.ts' />
module Game {
export class Sprite extends GameObject {
}
}
Post about it:
https://typescript.codeplex.com/workitem/1590
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With