What is the correct method to reference a static property in extended classes using JavaScript?
Consider the following javascript code:
class Animal {}
Animal.makeNoise = (language) => this.sounds[language];
class Dog extends Animal {}
Dog.sounds = {
english: 'woof-woof',
portuguese: 'au-au'
}
I attempted the following approach:
abstract class Animal {
static sounds: { [key in string]: false | string[] | string }
static makeNoise
= <S extends typeof Dog.sounds, L extends keyof S>(language: L): S[L]
=> this.sounds[language];
}
class Dog extends Animal {
static sounds: {
english: 'woof-woof',
portuguese: 'au-au'
}
}
Dog.makeNoise('english') // => "woof-woof"
However, I am struggling to find a way to access the this.sounds
of each extended class. Is there a proper solution to achieve this?