Skip to main content

Optionals (T?)

Optional or undefined values can be declared either by using the questionmark operator (?), or by adding an undefined variant:

interface Math extends HybridObject<{}> {
a?: number
b: number | undefined
}

In Kotlin/Java, nullables have to be boxed in object types.

Optionals vs null

In the same way that JavaScript distinguishes between an optional type/undefined and null, Nitro also has two separate concepts for the two.

An optional type (or undefined) represents a non-declared value, whereas null represents an explicit absence of a value. See Nulls for more information.