Lime Web Components API Documentation - v7.4.0
    Preparing search index...

    Function definePrimitive

    • Beta

      Identity helper for declaring a primitive. Returns its argument unchanged.

      The helper exists so TypeScript can infer TArgs from the annotation on build's parameter, and TReads from the reads tuple. Without it, the args shape must either be repeated as a variable type annotation, or TArgs falls back to its unknown default, discarding the args type at every downstream call site.

      Inferring TReads also narrows the predicate's scope.get, so reading a key that is not listed in reads is a compile error.

      Does not validate the id namespace, that check happens at runtime inside RuleRegistry.register.

      Type Parameters

      Parameters

      Returns RulePrimitive<TArgs, TReads>

      The same primitive, unchanged.

      import { definePrimitive } from '@limetech/lime-web-components';

      type OlderThanArgs = { days: number };

      const olderThan = definePrimitive({
      id: 'limetech.older-than',
      reads: ['limeobject'],
      build:
      ({ days }: OlderThanArgs) =>
      (scope) => {
      // @ts-expect-error 'user' is not listed in reads
      scope.get('user');

      return scope.get('limeobject') !== undefined && days > 0;
      },
      });