I am new to typescript and may be asking a beginner question. In my scenario, I have an array containing objects that all extend the same class. Here is an example:
class Body{
// implementation
}
class Rectangle extends Body{
// implementation
}
class Circle extends Body{
// implementation
}
const box: Rectangle = new Rectangle()
const circle: Circle = new Circle()
const world: Array<Body> = [box, circle]
The issue arises when I try to access methods on the elements in the array, as I receive an error stating they do not exist on the Body class (which is true). I'm unsure if I am approaching this correctly or making a mistake. Can anyone provide guidance on the correct method?