An error occurred in Typescript due to the lack of an argument being

Currently, I am facing a challenge while trying to incorporate inheritance into a game I am developing using typescript (pixi.js). The issue arises when I encounter this error. In my code, I have a class named Dog with the following implementation:

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

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

  }

Additionally, I have another class called Enemy, which serves as the superclass that Dog extends from. Here is how Enemy is structured:

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

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

However, within my dog.ts file, I encounter an error specifically under the line super(texture); in my code stating: "Expected 2 arguments, but got 1.ts(2554) enemy.ts(8, 38): An argument for 'game' was not provided."

This message has left me confused as I have provided an argument for the game parameter in enemy.ts and I am also extending from Pixi.sprite.

Update: Upon modifying the super in enemy.ts to super(texture, game), a new error surfaces reading: "Expected 0-1 arguments, but got 2.ts(2554)". This suggests that I can only pass one argument in the super function, hence highlighting the limitation of resolving the issue this way.

Consequently, upon further investigation, I realized that I had mistakenly modified the incorrect file initially.

Answer №1

You are seeing this error because the game argument was not provided in the super function call. To fix this issue, simply add game as the second argument in the super call within the Dog class:

super(texture, game);

Answer №2

It seems like in the constructor of Enemy, there should be two arguments:

texture: PIXI.Texture, game: Game
. However, you have only provided the first argument.

To fix this issue in your dog.ts, change

super(texture)

to

super(texture, game)

The same problem may occur in the Enemy class if the Pixi.Sprite also requires these two arguments.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Filtering an array of objects in real-time

var individuals = [ { Skin: "Bronze", Place: ["South"] }, { Skin: "Copper", Place: ["North", "South"] }, { Skin: "Copper", Place: ["North"] } ]; var requirements = [ { Field: "Skin", Values: ["Copper"] }, { Field: "Place", Values: ["North", "S ...

Incorporating personalized cells within Row Formatter in Tabulator

I'm currently experimenting with Tabulator (specifically React-Tabulator) to create a proof of concept for my project. One of the requirements for my project is to include buttons within the sections of my data trees. For example, I have departments ...

Guide to redirecting to a Laravel route upon receiving a call from JS Ajax

I am attempting to create a redirect to a specific route within a Laravel controller after the controller was called from an Ajax request in a JavaScript file. For example, I have accessed a view at localhost:8000/viewone, where I execute some JavaScript ...

The functionality of `config.assets.debug = true` fails to

I've encountered an issue with the configuration on development where config.assets.debug = true doesn't seem to work correctly. Instead of having multiple separate JavaScript and CSS file inclusions, I'm getting a consolidated one: <li ...

What is the best way to implement a dynamic dropdown list in an MVC3 application that is dependent on a specific element being selected?

I am trying to add a new DropDownFor on my View, but it should only appear if a specific SelectList item from the first DropDownFor is selected. Just to make things clear, let's say my first DropDownFor has two options: "A" and "B". If "B" is chosen, ...

GM_xmlhttpRequest Data Attribute Not Functioning Properly

I'm currently utilizing a grease monkey script to send a GM_xmlhttpRequest to my locally hosted asp.net web service. However, I've encountered an issue with the data attribute not functioning properly. Despite checking the Github repository, I ha ...

Configuring cloud code on Back4App to automatically trigger a POST API request to update the ESP

I am a beginner when it comes to developing APIs and cloud code, and I need help figuring out how to create an API that can add or update users in my back4app database table to my sendinblue (ESP) contact list. Could someone provide guidance on what shoul ...

Modify the h:outputText value dynamically with the power of jQuery!

Is it possible to use jQuery to dynamically change the value of my OutputText component? This is the code snippet for my component: <h:outputText id="txt_pay_days" value="0" binding="#{Attendance_Calculation.txt_pay_days}"/> I would apprecia ...

Adjust the content of a table cell using jQuery

<td>09 Mars 2020</td> Using the string above, I have created a div. Here are the Jquery variables I am working with: date1 = 09 Mars 2020 date2 = 18 Mars 2020 My goal is to combine the content from another date with the existing date to ach ...

Is it possible to define a namespaced external module in TypeScript?

Currently, I am dealing with some legacy js modules that are either namespaced on window or define'd if the page is using AMD. Here's an example: // foo/bar.js (function (root, factory) { if (typeof define === "function" && define.am ...

Placing emphasis on an object that appears following a period of waiting

I'm currently working on enhancing the accessibility of a slider that will be featured on my website. The goal is to create an effect where, after clicking (or pressing enter) on the first slide, the focus shifts to the second slide element, allowing ...

Why bother using useCallback in a component if React.memo is not utilized alongside it?

Here's an example to consider: const Child = () => { console.log("I did re-render!"); return null; }; const App = () => { const [_, setValue] = useState(); const fn = useCallback(() => { // do something }, []); ret ...

Despite using Jasime for my tests, Karma is returning an error and not executing any out of the zero tests I have

Here is the content of my karma/karma.conf.js: // Karma configuration // Generated on Mon Jan 04 2016 16:17:18 GMT-0500 (EST) module.exports = function(config) { // Configuration settings for Karma } Below is the code from karma/tests/test_p ...

"What is the best way to connect a md-input to the value of a md-slider

I'm in the process of developing an application using Angular 2.0/meteor, and I'm facing a challenge with binding an input to md-slider. Below is the HTML code for the component: <div class="panel-body"> <form [formGroup]="filtreFor ...

Show temporary information on the user's side in a table

To better explain the issue, please refer to the accompanying image. I am working with a Master/Detail form, specifically a Bill of Materials, which involves storing data in two separate database tables. The top portion of the form (Product, Quantity) is ...

What is a way to utilize Javascript in order to copy a JSON object by referencing a specific key within the object?

If you had the following JSON object example given, how could you utilize Javascript to replicate each object based on the value indicated in the "Count" key? Example Input: [ { "name":"David", "Count":2 }, { "name":"John", "Count":3 }, ] Desired Out ...

Unable to successfully rename an uploaded file utilizing Multer in the Express.js environment

While working on uploading a file from an HTML form using Express.js and Multer, I have successfully saved the file to a specific location (a folder named uploads). However, I am looking to rename the file during the upload process because Multer assigns ...

What is the method for setting the height of a CSS grid item and aligning a grid item to a specific side?

Recently, I've been working on my portfolio using a CSS grid to display cards as grid items. When viewed on mobile, the cards stack on top of each other, but on desktop, I have ensured that they are displayed next to each other. Lately, I have encoun ...

Testing Angular components: Mocking a service within another service or mocking an abstract class

I am looking to test a service that extends an abstract class. This abstract class includes the constructor and the method getId. Here is the code snippet: export abstract class ClientCacheService { private subscriptionId: string; protected getI ...

Next.js encountered a Runtime Error: Trying to access properties of undefined (specifically 'status') and failing

For those interested in viewing the code, it can be found here During the creation of a portfolio website using Next.js, I encountered an error. I am utilizing the latest version of Next.js (next 13.4.16) and incorporating the app router into my project. ...