Optional Type (?)

    Optional Type๐Ÿ”—

    You can indicate that a value is not required.

    Just append ? to the type.

    /// If provided, it must be an int; otherwise it can be omitted
    setting: int?
    

    Where ? Can Appear๐Ÿ”—

    While we say โ€œappend ? to the typeโ€, strictly speaking you can place ? after a type name or after an array type.

    /// Either int? or [int]
    /// Equivalent to writing int? | [int]?
    setting: int? | [int]
    
    • Inside arrays
    /// This is an array of int?
    /// In JSON, values like [null, 100] are allowed.
    /// In languages without null like TOML, only an empty array can represent absence.
    setting: [int?]
    
    • Not allowed
    /// This form is not allowed!
    setting: int |?