mobx-keystone
    Preparing search index...

    Function tProp

    • 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

      • defaultValue: string

        Default value.

      Returns OptionalModelProp<string>

    • 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

      • defaultValue: number

        Default value.

      Returns OptionalModelProp<number>

    • 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

      • defaultValue: boolean

        Default value.

      Returns OptionalModelProp<boolean>

    • 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

      • TType extends AnyType

        Type checker type.

      Parameters

      Returns OptionalModelProp<TypeToData<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

      • TType extends AnyType

        Type checker type.

      Parameters

      Returns OptionalModelProp<TypeToData<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

      • TType extends AnyType

        Type checker type.

      Parameters

      • type: TType

        Type checker.

      Returns MaybeOptionalModelProp<TypeToData<TType>>