I try to use a static member from an instance method. I know about accessing static member from non-static function in typescript, but I do not want to hard code the class to allow inheritance:
class Logger {
protected static PREFIX = '[info]';
public log(msg: string) {
console.log(Logger.PREFIX + ' ' + msg); // What to use instead of Logger` to get the expected result?
}
}
class Warner extends Logger {
protected static PREFIX = '[warn]';
}
(new Logger).log('=> should be prefixed [info]');
(new Warner).log('=> should be prefixed [warn]');
I've tried things like
typeof this.PREFIX
ClassName.property
. For overridden properties,(<typeof ClassName> this.constructor).property
. – Dick