export type JsonType = | null | string | number | boolean | JsonObject | JsonArray; export type Serializer = (target: T) => JsonType; export type Deserializer = ( data: JsonType, target?: T, instantiationMethod?: InstantiationMethod ) => T; export type IConstructable = { constructor: Function }; export type SerializeFn = (data: T) => JsonType; export type SerializablePrimitiveType = | DateConstructor | NumberConstructor | BooleanConstructor | RegExpConstructor | StringConstructor; /** * #### InstantiationMethod.New: * The constructor will be invoked when a new instance needs to be created. * * #### InstantiationMethod.ObjectCreate: * The object will be created without invoking its constructor, which is useful for systems where constructed objects immediately freeze themselves * * #### InstantiationMethode.None: * *deserializeXXX* functions will return a plain object instead, which can be useful for systems like Redux that expect / require plain objects and not class instances. */ export enum InstantiationMethod { None = 0, New = 1, ObjectCreate = 2, } export interface JsonObject extends Indexable {} export interface JsonArray extends Array {} export interface ISerializer { Serialize: Serializer; Deserialize: Deserializer; } export interface Indexable { [idx: string]: T; } export interface SerializableType { new (...args: any[]): T; onSerialized?: (data: JsonObject, instance: T) => JsonObject | void; onDeserialized?: ( data: JsonObject, instance: T, instantiationMethod?: InstantiationMethod ) => T | void; } export interface CerializrAsJsonOptions { keyName: string; transformKey: boolean; }