Function: prop()
Call Signature
function prop<TValue>(defaultFn): OptionalModelProp<TValue>;
Defines a model property, with an optional function to generate a default value
if the input snapshot / model creation data is null or undefined.
Example:
x: prop(() => 10) // an optional number, with a default value of 10
x: prop<number[]>(() => []) // an optional number array, with a default empty array
Type Parameters
| Type Parameter | Description |
|---|---|
TValue | Value type. |
Parameters
| Parameter | Type | Description |
|---|---|---|
defaultFn | () => TValue | Default value generator function. |
Returns
OptionalModelProp<TValue>
Call Signature
function prop<TValue>(defaultValue): OptionalModelProp<TValue>;
Defines a model property, with an optional default value
if the input snapshot / model creation data is null or undefined.
You should only use this with primitive values and never with object values
(array, model, object, etc).
Example:
x: prop(10) // an optional number, with a default value of 10
Type Parameters
| Type Parameter | Description |
|---|---|
TValue | Value type. |
Parameters
| Parameter | Type | Description |
|---|---|---|
defaultValue | Exclude<TValue> | Default primitive value. |
Returns
OptionalModelProp<TValue>
Call Signature
function prop<TValue>(): MaybeOptionalModelProp<TValue>;
Defines a model property with no default value.
Example:
x: prop<number>() // a required number
x: prop<number | undefined>() // an optional number, which defaults to undefined
Type Parameters
| Type Parameter | Description |
|---|---|
TValue | Value type. |
Returns
MaybeOptionalModelProp<TValue>