Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when constructing Dog: Expected 0 arguments, but got 1.ts(2554) #62

Open
fckaye opened this issue Oct 18, 2023 · 0 comments
Open

Comments

@fckaye
Copy link

fckaye commented Oct 18, 2023

On Chapter 2, Creating your first TypeScript class.

After following the required steps, and creating the Dog class, I get an error inside the super() with the following error:
Expected 0 arguments, but got 1.ts(2554)

This is the Dog class (inside a file called Dog.ts):

import { Animal, FoodChainType } from "./Animal";

class Dog extends Animal {
  constructor() {
    super({
      name: "Dog",
      sound: "Wof!",
      family: "Canidae",
      foodChainType: FoodChainType.Carnivorous,
    });
  }
}

This is Animal.ts, inside the same folder:

export enum FoodChainType {
  Carnivorous = "carnivorous",
  Herbivorous = "herbivorous",
  Omnivorous = "omnivorous",
}

interface IAnimal {
  name: string;
  sound?: string;
  family: string;
  foodChainType: FoodChainType;
}

interface IAnimalConstructor extends IAnimal {}

interface IBasicAnimal extends IAnimal {
  whoAmI: () => void;
  makeSound: () => void;
}

export class Animal implements IBasicAnimal {
  public name: string;
  public sound: string;
  public family: string;
  public foodChainType: FoodChainType;

  consructor(params: IAnimalConstructor) {
    this.name = params.name;
    this.sound = params.sound || "";
    this.family = params.family;
    this.foodChainType = params.foodChainType;
  }

  public whoAmI(): void {
    console.log(
      `I am a ${this.name}, my family is ${this.family}. My diet is ${this.foodChainType}.`
    );
    if (this.sound) {
      console.log([...Array(2).fill(this.sound)].join(", "));
    }
  }

  public makeSound(): void {
    console.log(this.sound);
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant