2.4.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 question mark ?:

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;
}
since Haxe 4.0.0

A structure field can be declared as optional in the class notation by prefixing its name with a question mark ?:

typedef User = {
  var age : Int;
  var name : String;
  var ?phoneNumber : String;
}