I am trying to work with an abstract class in TypeScript, which includes an enum and a method:
export enum SingularPluralForm {
SINGULAR,
PLURAL
};
export abstract class Dog {
// ...
}
Now, I have created a subclass that extends the abstract class and includes some properties:
export class Pug extends Dog {
// ...
static readonly kindNames = {
[SingularPluralForm.SINGULAR]:
'pug',
[SingularPluralForm.PLURAL]:
'pugs'
};
// ...
}
In addition, I need to implement a parameterized class that uses generics and wants access to the kindNames
property:
export class Playground<T extends Dog> {
// ...
getKindName(form: SingularPluralForm) {
// How can I retrieve T.kindNames[form] here?
}
// ...
}
Could someone please guide me on how to access T.kindNames[form]
within this setup?
Your assistance is greatly appreciated. Thank you.
Update 1: Passing the Pug
class to the constructor of Playground
seems like a solution, but unfortunately, the Playground
class is an Angular component initialized by the framework, not manually. :-(