Optional class members in Typescript

The following works in TypeScript 3.x:

class Foo {
  a?: string;
  b?: string;
  c: number = 123;
}

Note that you need to initialise any members that are not optional (either inline as shown or in the constructor).

Leave a Comment