Home > scrubbr > Scrubbr > serialize
Scrubbr.serialize() method¶
Serialize data based on a TypeScript type.
You can influence the return type by using the generic angle brackets:
Signature:
serialize<SerializedType = any>(schemaType: string, data: unknown, context?: ContextObject, options?: ScrubbrOptions): SerializedType;
Parameters¶
Parameter | Type | Description |
---|---|---|
schemaType | string | The name of the typescript type to serialize the data with. |
data | unknown | The data to serialize |
context | ContextObject | Any data you want sent to the custom serializer functions. |
options | ScrubbrOptions | Set options for just this serialization. |
Returns:
SerializedType
Example¶
scrubbr.serialize<UserList>('UserList', data);