You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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);
}
}
The text was updated successfully, but these errors were encountered:
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):
This is Animal.ts, inside the same folder:
The text was updated successfully, but these errors were encountered: