AlphaThe primitive definition.
The same primitive, unchanged.
The args shape lives only on build's parameter. TypeScript infers
TArgs = OlderThanArgs and TReads = 'limeobject', so
scope.get('user') inside build would be a compile error.
type OlderThanArgs = { days: number };
const olderThan = definePrimitive({
id: 'limetech.older-than',
reads: ['limeobject'],
build: ({ days }: OlderThanArgs) => (scope) =>
scope.get('limeobject') !== undefined && days > 0,
});
Identity helper for declaring a primitive. Returns its argument unchanged.
The helper exists so TypeScript can infer
TArgsfrom the annotation onbuild's parameter, andTReadsfrom thereadstuple. Without it, the args shape must either be repeated as a variable type annotation, orTArgsfalls back to itsunknowndefault, discarding the args type at every downstream call site.Does not validate the
idnamespace, that check happens at runtime inside RuleRegistry.register.