Options

In this section you'll learn how to configure the revival process.

The options are specified as the third argument of the `revive` function.

import { revive } from 'revivejs'

const model = revive(json, schema, options)

The structure of the options argument is the following

interface RevivalOptions {
  failOnUnknownFields?: boolean;
  failOnMissingFields?: boolean;
  noNewObjects?: boolean;
}

Option

Description

failOnUnknownFields

If true the function will throw a `TypeError` exception if an unknown field is found in the schema. A field is unknown if it is not part of the model properties.

failOnMissingFields

If true the function will throw a TypeError exception if a model property is not found in the json input.

noNewObjects

If true the function will not construct new objects based on the schema. Instead it will simply set the prototype to the simple javascript objects created by the JSON.parse call when parsing the json input. Think Object.setPrototypeOf() This is useful if you already have an object and you want to assign behavior to it and its nodes.

The default options are the following

const defaultReviveOptions: ReviveOptions = {
  failOnUnknownFields: false,
  failOnMissingFields: false,
  noNewObjects: false,
}

Last updated

Was this helpful?