@metreeca/core - v0.12.0
    Preparing search index...

    Type Alias State<T>

    State: object & {
        [K in keyof T]: T[K] extends Transition<infer O, never>
            ? O extends T ? T[K] : never
            : T[K]
    }

    State contract.

    The contract a state type is held to, as an immutable object combining:

    • Version Data - Data properties describing the current state
    • Transition Methods - Methods with signature like transition(...inputs): this that take inputs and generate a new immutable state with updated version data

    Type Parameters

    • T

      The state type being constrained

    Declaration

    • State types are declared as plain interfaces or object types, with no base to extend: they are admitted wherever this module declares a state type parameter, bound as T extends State<T>
    • A method returning anything other than the state itself is refused by the compiler where the state type is supplied, as are non-object types
    • Read-only data properties are a contract the compiler cannot enforce, since readonly modifiers don't take part in assignability

    Immutability

    • States are immutable: members are read-only, so a write is refused by the compiler rather than throwing at run time, and every change goes through a transition method
    • Transition methods return new immutable States

    Transitions

    • Transition methods can be destructured and called independently (e.g., const { increment } = state; increment();)