In my code, I have a base class called Animal
which contains some methods. There is also a subclass of this class named Bird
, which overrides one of the parent methods to handle a specific edge case.
The structure of these classes is as follows:
class Animal {
constructor(animal) {
this.animal = animal;
}
public define(){
return {name: this.animal.name}
}
}
class Bird extends Animal{
public define(){
return {color: this.animal.color}
}
}
When calling bird.define()
, everything seems to work fine. However, TypeScript raises an error stating:
Property 'define' in type 'Bird' is not assignable to the same property in base type 'Animal'. Type '() => { color: string; }' is not assignable to type '() => { name: string }'. Type '{ color: string; }' is missing the following properties from type '{ name: string; }':
name
Is there a way to address this issue without resorting to using ts-ignore
?