Interface TypeDefinition<TInstance, TSerialized>

Definition for a custom type that can be serialized/deserialized

interface TypeDefinition<TInstance, TSerialized> {
    create?: (() => TInstance);
    deserialize: ((data: TSerialized) => TInstance);
    id: string;
    is: ((obj: unknown) => obj is TInstance);
    serialize: ((obj: TInstance) => TSerialized);
    strategy?: "value" | "ref";
}

Type Parameters

  • TInstance = unknown
  • TSerialized = unknown

Properties

create?: (() => TInstance)

Optional factory used to create a placeholder during deserialization

deserialize: ((data: TSerialized) => TInstance)

Function to deserialize the data back to the original object

id: string

Unique identifier for the type

is: ((obj: unknown) => obj is TInstance)

Predicate function to check if an object matches this type

serialize: ((obj: TInstance) => TSerialized)

Function to serialize the object

strategy?: "value" | "ref"

Serialization strategy: 'value' (inline, no identity) or 'ref' (graph node, identity preserved). Default: 'ref'