Currently, I am delving into typescript and have stumbled upon a peculiar behavior. It seems there are multiple instances of a static property in this scenario; one for the person
class and another for the student
class. To my surprise, while exploring similar situations in other languages like C#, I discovered that there is only one instance shared by the declaring class and all classes derived from it.
class person
{
name : string
static maxAge : number
constructor(name:string)
{
this.name = name
}
}
class student extends person
{
standard : string
constructor(name:string,standard : string)
{
super(name);
this.standard = standard;
}
}
person.maxAge = 120;
console.log(person.maxAge);
console.log(student.maxAge);
Here are some burning questions on my mind:
- I'm curious as to why the static property is not shared with the derived class.
- Could it be possible that the compiler is overlooking something crucial here, thereby failing to flag any compilation errors?