Type Alias WithoutStaticData<C, B>

WithoutStaticData: C & {
    readonly [K in Exclude<keyof C, keyof B> as C[K] extends | (
        (...args: never) => unknown
    )
    | (abstract new (...args: never) => unknown)
        ? never
        : K]: never
}

The class C once it keeps no static data: every public static member it adds to those of its base class B, its own or inherited, is a function, such as a method. A step, a rescue step or a policy compiles only as such a class, since everything built from it would share a static property holding anything else; the error names the property. A protected or private static, which no type can see, and a static accessor typed as a function compile, but are refused when the class is declared or its builder is started.

import assert from "node:assert/strict";
import { type Outcome, Step, step } from "itinera/step";

@step()
class Ship extends Step {
static parcels(grams: number): number {
return Math.ceil(grams / 20_000);
}

override run(): Outcome {
return this.succeed();
}
}

class Counted extends Step {
static shipped = 0;

override run(): Outcome {
Counted.shipped += 1;
return this.succeed();
}
}

assert.equal(Ship.parcels(45_000), 3);
assert.throws(() => {
// @ts-expect-error: a step keeps no static data
Counted.builder("counted");
}, /step Counted keeps static data, which everything built from it would share: shipped/);

Type Parameters

  • C

    The class.

  • B

    Its base class, such as typeof Step.