Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Typescript an argument was not provided

I’m trying to implement inheritence in a game i’m making with typescript (pixi.js) but I’m getting stuck on this error. I have a class, Dog, with the following code:

export class Dog extends Enemy {
  //private game: Game;
  //private speed: number = 0;

  constructor(texture: PIXI.Texture, game: Game) {
    super(texture);
    this.game = game;

  }

I also have a class enemy, which the class dog extends to, with the following code:

export class Enemy extends PIXI.Sprite {
  public game: Game;
  public speed: number = 0;

  constructor(texture: PIXI.Texture, game: Game) {
    super(texture);
    this.game = game;
  }

But in my dog.ts file I get the following error under the super(texture); part of my code: Expected 2 arguments, but got 1.ts(2554)
enemy.ts(8, 38): An argument for ‘game’ was not provided.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I have no idea what this means as I would expect I have given an argument for game in enemy.ts and I also extend to Pixi.sprite.

Edit: If i change the super in enemy.ts to super(texture, game) I get the following error: if I do this I get the following error: Expected 0-1 arguments, but got 2.ts(2554)

I can only put on argument in the super function so I’m afraid this won’t fix the problem

Edit 2: Nvm I changed the wrong file

>Solution :

Because you did not provide game (which is a required argument) in super.
In the Dog class add game parameter to the super function:

super(texture, game);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading