• For mutually recursive types

    Example

    type Leaf = number;
    type Node = [Tree, Tree];
    type Tree = Node | Leaf;
    const { tree } = fc.letrec<{ tree: Tree, node: Node, leaf: Leaf }>(tie => ({
    tree: fc.oneof({depthSize: 'small'}, tie('leaf'), tie('node')),
    node: fc.tuple(tie('tree'), tie('tree')),
    leaf: fc.nat()
    }));
    // tree is 50% of node, 50% of leaf
    // the ratio goes in favor of leaves as we go deeper in the tree (thanks to depthSize)

    Remarks

    Since 1.16.0

    Type Parameters

    • T

    Parameters

    • builder: T extends Record<string, unknown> ? LetrecTypedBuilder<T> : never

      Arbitraries builder based on themselves (through tie)

    Returns LetrecValue<T>

  • For mutually recursive types

    Example

    const { tree } = fc.letrec(tie => ({
    tree: fc.oneof({depthSize: 'small'}, tie('leaf'), tie('node')),
    node: fc.tuple(tie('tree'), tie('tree')),
    leaf: fc.nat()
    }));
    // tree is 50% of node, 50% of leaf
    // the ratio goes in favor of leaves as we go deeper in the tree (thanks to depthSize)

    Remarks

    Since 1.16.0

    Type Parameters

    • T

    Parameters

    Returns LetrecValue<T>

Generated using TypeDoc