1

Sorry if it is a duplicate question, I can't find it...
I want to write out a property, but still keep it nullable.

I want

public foo?: string;

to be (but nullable)

  private _foo: string;
  public get foo(): string {
    return this._foo;
  }
  public set foo(v: string) {
    // some logic with 'v'...
    this._foo = v;
  }

Where do I put my ? or is there another way?
I tried with Nullable<string> but it doesn't work either.

Hypenate
  • 1,907
  • 3
  • 22
  • 38

1 Answers1

2

You can write

private _foo: string|null;
public get foo(): string|null {
  return this._foo;
}
public set foo(v: string|null) {
  this._foo = v;
}
R3tep
  • 12,512
  • 10
  • 48
  • 75