Nullable types
// Example 1: create a nullable variable by evolution.
let x = null;
set x = 1;
// Example 2: create a nullable variable by explicit type annotation.
let y: number? = 1;
set y = null;
// Example 3: create a non-nullable variable.
let z = 1;
set z = null; // ERROR: Expected a 'number' but the term has type 'null'.Refining nullable values
// Example: we imagine that we have received an non-local variable "totalPrice"
// which is a nullable number. We try to use the variable in a calculation.
// This gives a design-time error.
// ERROR: Expected a 'number' but the term has type 'number?'
let discountedPrice = totalPrice * 0.8;Primitive
Last updated
Was this helpful?