Quite straight question on how to write clean code here. Assuming I have a property with a backing field:
get value(): string { return this._value; }
set value(v: string) { this._value = v; }
private _value?: string;
this code is invalid since _value
is undefined by default. To I actually have to write
get value(): string | undefined { return this._value; }
each time? Is there no shorthand? Looks pretty creepy to me. If I now accept null values, too, I’d have to write
get value(): string | undefined | null { return this._value; }
set value(v: string | null) { this._value = v; }
private _value?: string | null;
every time. Nicer solution? Or is as it is?