bunqueue v2.8 API referenceall versions · guide
bunqueue
    Preparing search index...

    Interface StepOptions<TInput, TSteps>

    Options for a single step.

    TSteps is part of the signature for source compatibility and for symmetry with TypedStepHandler, even though compensate no longer narrows on it (see below). Removing the parameter would break every explicit StepOptions<In, Steps> in user code.

    interface StepOptions<
        TInput = unknown,
        TSteps extends Record<string, unknown> = Record<string, unknown>,
    > {
        compensate?(
            ctx: StepContext<TInput, TSteps extends never ? never : any>,
        ): void | Promise<void>;
        inputSchema?: SchemaLike;
        outputSchema?: SchemaLike;
        retry?: number;
        timeout?: number;
    }

    Type Parameters

    • TInput = unknown
    • TSteps extends Record<string, unknown> = Record<string, unknown>
    Index
    inputSchema?: SchemaLike

    Validate step input before execution

    outputSchema?: SchemaLike

    Validate step output after execution

    retry?: number
    timeout?: number
    • A METHOD taking a permissively-typed context, and every part of that is load bearing. Three forms were measured against real handler shapes:

      shape union method method compensate: async (ctx) => ... TS7006 ok ok annotated with steps it reads ok ok ok annotated with a step that does not exist ok TS2322 ok CompensateHandler alias ok ok ok

      Not a union (TypedCompensateHandler | CompensateHandler): TypeScript cannot contextually type a parameter against a union of signatures, so the inline arrow every documented example uses was an implicit any and failed noImplicitAny.

      A method rather than a property so parameters stay bivariant under strictFunctionTypes, which is what lets an explicitly annotated handler through.

      any rather than TSteps for the step map, deliberately: with TSteps an annotation naming a step this workflow does not declare is rejected, and the published union accepted it. Keeping the looser map costs typed access to ctx.steps inside a rollback, which handlers already narrow with a cast in practice, and buys source compatibility with every handler written before.

      Parameters

      Returns void | Promise<void>