dehydrate()function

dehydrate(value: unknown, hydrations: Hydrations): unknown
ParamType
valueunknown
The value to dehydrate. required
hydrationsHydrations
The set of $type keys mapped to the class constructors used to recognise instances. required
Return
unknown
The dehydrated version of the specified value.
Throws
unknown
ValueError If the value is a class instance that cannot be dehydrated (i.e. is not matched by any constructor in hydrations).

Deeply dehydrate a class instance based on a set of Hydrations

  • Dehydration allows you to pass class instances from a server back to a client.
  • By its nature dehydration is an unsafe operation.
  • Deeply iterates into arrays and plain objects to dehydrate their items and props too.
  • Note: the recursion in this function does not currently protect against infinite loops.

Examples

dehydrate(new Date(0), {}) // { $type: "Date", $value: 0 }