Function prop

  • 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

    • TValue

    Parameters

    Returns OptionalModelProp<TValue>

    TValue Value type.

  • 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

    • TValue

    Parameters

    • defaultValue: Exclude<TValue, object>

      Default primitive value.

    Returns OptionalModelProp<TValue>

    TValue Value type.

  • 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

    • TValue

    Returns MaybeOptionalModelProp<TValue>

    TValue Value type.