An abstract class that overrides the toJSON() method to serialize private attributes

Only underscored values are serialized!

Example

class MyClass extends Serializable {
private _myNumber = 69;
private _myString = '420';
myNotSerializedValue = 13;
// ... not serialized constructor and methods ...
}

console.log(new MyClass().toJSON());
// { myNumber: 69, myString: "420" }

Hierarchy

Methods

Methods

  • 💬 reduces the Serializable to its private ("underscored") attributes.

    All non-underscored attributes and methods will be omitted. This method overrides the built-in toJSON() which is primarily used in JSON.stringify()

    Returns

    an object containing all private attributes

    Type Parameters

    • Key extends "toJSON"

    • Value extends (<Key, Value>() => Record<Key extends `_${X}` ? X : never, Value>)

    Returns Record<Key extends `_${X}` ? X : never, Value>

Generated using TypeDoc