Optional values and narrowing¶
Unobin checks null strictly. A value of type optional(T) cannot be used where T is required until the source accounts for null.
Declaring optional values¶
inputs: {
greeting: { type: optional(string) }
tls: { type: optional(object({ cert: optional(string) })) }
}
A declaration default provides a value when the input is omitted. For an optional declaration, null follows the same default path:
Null tests¶
A null test narrows the value where the test proves it is set:
The else branch sees input.greeting as string.
Guarded navigation¶
Use ?. to read through a maybe-null object:
The result is still optional. Use ?? to provide a fallback:
Comprehension filters¶
A when filter can narrow element fields:
Constraint guards¶
A constraint can use when to guard the require expression: