One solution not discussed by this answer is to implement a get method in a derived class which returns a string literal (but not member property as this would essentially be the same issue):
class Base {
constructor() { console.log( this.color ) }
public get color(): string { return 'blue' }
}
class Literal extends Base {
public get color(): string { return 'red' }
}
class Member extends Base {
private _color: string = 'green'
public get color(): string { return this._color }
}
let b = new Base() // => 'blue'
let l = new Literal() // => 'red'
let m = new Member() // => undefined
Are there any issues/downfalls to using this approach, for example with efficiency, in the emitted JavaScript - as opposed to the solutions provided in the linked answer?