I’m trying to implement something like instanceLikesFood()
below, but I also want to inherit the child’s changes to the static methods.
class BaseClass {
private static likedFoodsByType = ["tacos"];
constructor(private readonly individualLikes: string[]);
public static typeLikesFood(food: string): boolean {
return !!this.likedFoodsByType.find(food);
}
public instanceLikesFood(food: string): boolean {
// instead of using BaseClass.likedFoodsByType, I want to get the child's overrides
return !!BaseClass.likedFoodsByType.find(food) || !!this.individualLikes.find(food);
}
}
class ChildClass extends BaseClass {
private static override likedFoodsByType = [...super.likedFoodsByType, "burritos"];
}
const childObj = new ChildClass("enchiladas")
In the example above, I believe childObj.instanceLikesFood("burritos")
would return false, but I’d want it to return true.
jordaniel is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1