2.5.3 Optional Fields

Fields of a structure type can be made optional. In the standard notation, this is achieved by prefixing the field name with a ?:

typedef User = {
  age : Int,
  name : String,
  ?phoneNumber : String

In class notation, the @:optional metadata can be used instead:

typedef User = {
  var age : Int;
  var name : String;
  @:optional var phoneNumber : String;

Take the Haxe Survey!