Function: tProp()
Call Signature
function tProp(defaultValue): TypedOptionalModelProp<IdentityType<string>>;
Defines a string model property with a default value.
Equivalent to tProp(types.string, defaultValue).
Example:
x: tProp("foo") // an optional string that will take the value `"foo"` when undefined.
Parameters
| Parameter | Type | Description |
|---|---|---|
defaultValue | string | Default value. |
Returns
TypedOptionalModelProp<IdentityType<string>>
Call Signature
function tProp(defaultValue): TypedOptionalModelProp<IdentityType<number>>;
Defines a number model property with a default value.
Equivalent to tProp(types.number, defaultValue).
Example:
x: tProp(42) // an optional number that will take the value `42` when undefined.
Parameters
| Parameter | Type | Description |
|---|---|---|
defaultValue | number | Default value. |
Returns
TypedOptionalModelProp<IdentityType<number>>
Call Signature
function tProp(defaultValue): TypedOptionalModelProp<IdentityType<boolean>>;
Defines a boolean model property with a default value.
Equivalent to tProp(types.boolean, defaultValue).
Example:
x: tProp(true) // an optional boolean that will take the value `true` when undefined.
Parameters
| Parameter | Type | Description |
|---|---|---|
defaultValue | boolean | Default value. |
Returns
TypedOptionalModelProp<IdentityType<boolean>>
Call Signature
function tProp<TType>(type, defaultFn): TypedOptionalModelProp<TType>;
Defines a model property, with an optional function to generate a default value
if the input snapshot / model creation data is null or undefined and with an associated type checker.
Example:
x: tProp(types.number, () => 10) // an optional number, with a default value of 10
x: tProp(types.array(types.number), () => []) // an optional number array, with a default empty array
Type Parameters
| Type Parameter | Description |
|---|---|
TType extends AnyType | Type checker type. |
Parameters
| Parameter | Type | Description |
|---|---|---|
type | TType | Type checker. |
defaultFn | () => TypeToData<TType> | Default value generator function. |
Returns
TypedOptionalModelProp<TType>
Call Signature
function tProp<TType>(type, defaultFn): TypedOptionalModelProp<TType[number]>;
Defines a model property using array syntax as a shorthand for types.or(...),
with an optional function to generate a default value if the input snapshot /
model creation data is null or undefined.
Example:
x: tProp([String, Number], () => 10) // equivalent to tProp(types.or(String, Number), () => 10)
Type Parameters
| Type Parameter | Description |
|---|---|
TType extends readonly AnyType[] | Array of possible type checkers. |
Parameters
| Parameter | Type | Description |
|---|---|---|
type | TType | Array shorthand for types.or(...). |
defaultFn | () => TypeToData<TType[number]> | Default value generator function. |
Returns
TypedOptionalModelProp<TType[number]>
Call Signature
function tProp<TType>(type, defaultValue): TypedOptionalModelProp<TType>;
Defines a model property, with an optional default value
if the input snapshot / model creation data is null or undefined and with an associated type checker.
You should only use this with primitive values and never with object values
(array, model, object, etc).
Example:
x: tProp(types.number, 10) // an optional number, with a default value of 10
Type Parameters
| Type Parameter | Description |
|---|---|
TType extends AnyType | Type checker type. |
Parameters
| Parameter | Type | Description |
|---|---|---|
type | TType | Type checker. |
defaultValue | TypeToData<TType> | Default value generator function. |
Returns
TypedOptionalModelProp<TType>
Call Signature
function tProp<TType>(type, defaultValue): TypedOptionalModelProp<TType[number]>;
Defines a model property using array syntax as a shorthand for types.or(...),
with an optional default value if the input snapshot / model creation data is
null or undefined.
Example:
x: tProp([String, Number], "foo") // equivalent to tProp(types.or(String, Number), "foo")
Type Parameters
| Type Parameter | Description |
|---|---|
TType extends readonly AnyType[] | Array of possible type checkers. |
Parameters
| Parameter | Type | Description |
|---|---|---|
type | TType | Array shorthand for types.or(...). |
defaultValue | TypeToData<TType[number]> | Default value. |
Returns
TypedOptionalModelProp<TType[number]>
Call Signature
function tProp<TType>(type): TypedMaybeOptionalModelProp<TType>;
Defines a model property with no default value and an associated type checker.
Example:
x: tProp(types.number) // a required number
x: tProp(types.maybe(types.number)) // an optional number, which defaults to undefined
Type Parameters
| Type Parameter | Description |
|---|---|
TType extends AnyType | Type checker type. |
Parameters
| Parameter | Type | Description |
|---|---|---|
type | TType | Type checker. |
Returns
TypedMaybeOptionalModelProp<TType>
Call Signature
function tProp<TType>(type): TypedMaybeOptionalModelProp<TType[number]>;
Defines a model property with no default value using array syntax as a shorthand
for types.or(...).
Example:
x: tProp([String, undefined]) // equivalent to tProp(types.or(String, undefined))
Type Parameters
| Type Parameter | Description |
|---|---|
TType extends readonly AnyType[] | Array of possible type checkers. |
Parameters
| Parameter | Type | Description |
|---|---|---|
type | TType | Array shorthand for types.or(...). |
Returns
TypedMaybeOptionalModelProp<TType[number]>