Function createModelSchema

  • Creates a model schema that (de)serializes an object created by a constructor function (class). The created model schema is associated by the targeted type as default model schema, see setDefaultModelSchema. Its factory method is () => new clazz() (unless overriden, see third arg).

    Example

    function Todo(title, done) {
    this.title = title
    this.done = done
    }

    createModelSchema(Todo, {
    title: true,
    done: true,
    })

    const json = serialize(new Todo('Test', false))
    const todo = deserialize(Todo, json)

    Returns

    model schema

    Type Parameters

    • T extends object

    Parameters

    • clazz: Clazz<T>

      class or constructor function

    • props: Props<any>

      property mapping

    • Optional factory: ((context: default<any>) => T)

      optional custom factory. Receives context as first arg

        • (context: default<any>): T
        • Parameters

          • context: default<any>

          Returns T

    Returns ModelSchema<T>

Generated using TypeDoc