Problem
I encountered a roadblock while following a tutorial. When I call the 'bark()' method in the ShelterDog class, the browser console displays <empty string>
instead of the expected output "WOOF WOOF!!!"
Code
// Dog.ts
export default class Dog {
constructor(
public name: string,
public breed: string,
public age: number
) {}
bark():void {
console.log("WOOF WOOF!!!");
}
}
// ShelterDog.ts
import Dog from "./Dog.js";
export default class ShelterDog extends Dog {
constructor(
name: string,
breed: string,
age: number,
public shelter: string
) {
super(name, breed, age);
this.shelter = shelter
}
}
// index.ts
import Dog from "./Dog.js"
import ShelterDog from "./ShelterDog.js"
const elton = new Dog("Elton", "Aussie", 0.5)
elton.bark()
const benton = new ShelterDog("Benton","Madman",99,"Chaos Refuge")
benton.bark()