isguard-ts
    Preparing search index...

    Function isLazy

    • Creates a LazyTypeGuard that evaluates the generator function only when needed.

      This is useful for:

      • Resolving circular imports.
      • Defining recursive type guards (e.g. trees, linked lists).

      Type Parameters

      • T

        The type to guard

      Parameters

      • generator: () => TypeGuard<T>

        A function that returns the actual type guard when called

      Returns LazyTypeGuard<T>

      A type guard for T

      const isPeople = isLazy(() => isPerson).array();
      
      type Tree = { value: number; left?: Tree; right?: Tree };

      const isTree: TypeGuard<Tree> = isType<Tree>({
      value: isNumber,
      left: isLazy(() => isTree).optional(),
      right: isLazy(() => isTree).optional(),
      });