Kaizen
Browse modulesRulesrules/sharedTypes

Type Alias: CustomConditionDef<TConfig, TContext>

type CustomConditionDef<TConfig, TContext> = {
  conditionType: string;
  configSchema: z.ZodType<TConfig>;
  handler: boolean;
};

Defined in: shared/rules/types/engine.ts:71

A custom (non-built-in) condition definition. Passed inline via the customConditions option on matchRules(). Custom conditions take precedence over built-ins — supply a definition with a matching conditionType to override a built-in handler entirely.

Note: matchRules() accepts CustomConditionDef<unknown, TContext>[] because the array is heterogeneous — each element has its own TConfig derived from its own configSchema. TypeScript lacks first-class existentials, so we widen to unknown at the array boundary; the handler's config is re-typed at runtime via configSchema.parse() inside evaluateCondition.

handler is declared as a method (not an arrow-style property) so TypeScript checks its parameters bivariantly under strictFunctionTypes. Without that, a caller's CustomConditionDef<{ tier: string }, T> would not be assignable to CustomConditionDef<unknown, T>[] because arrow-style properties are checked contravariantly. The bivariance is sound here: the engine only ever invokes the handler with a config that came from configSchema.parse(...), so the runtime type matches the declared TConfig regardless of how TypeScript widens it at the array boundary.

Time-aware custom handlers should manage their own evaluation date (e.g. DateTime.now() with a per-condition evaluation_date_field override), mirroring the built-in handlers. The engine no longer threads a clock through dispatch.

Type Parameters

Type Parameter
TConfig
TContext

Properties

conditionType

conditionType: string;

Defined in: shared/rules/types/engine.ts:72


configSchema

configSchema: z.ZodType<TConfig>;

Defined in: shared/rules/types/engine.ts:73

Methods

handler()

handler(config: TConfig, resolve: Resolve<TContext>): boolean;

Defined in: shared/rules/types/engine.ts:74

Parameters

ParameterType
configTConfig
resolveResolve<TContext>

Returns

boolean

On this page