UNPKG

876 BTypeScriptView Raw
1import { Arbitrary } from '../check/arbitrary/definition/Arbitrary';
2/**
3 * Output type for {@link memo}
4 * @remarks Since 1.16.0
5 * @public
6 */
7export declare type Memo<T> = (maxDepth?: number) => Arbitrary<T>;
8/**
9 * For mutually recursive types
10 *
11 * @example
12 * ```typescript
13 * // tree is 1 / 3 of node, 2 / 3 of leaf
14 * const tree: fc.Memo<Tree> = fc.memo(n => fc.oneof(node(n), leaf(), leaf()));
15 * const node: fc.Memo<Tree> = fc.memo(n => {
16 * if (n <= 1) return fc.record({ left: leaf(), right: leaf() });
17 * return fc.record({ left: tree(), right: tree() }); // tree() is equivalent to tree(n-1)
18 * });
19 * const leaf = fc.nat;
20 * ```
21 *
22 * @param builder - Arbitrary builder taken the maximal depth allowed as input (parameter `n`)
23 *
24 * @remarks Since 1.16.0
25 * @public
26 */
27export declare function memo<T>(builder: (maxDepth: number) => Arbitrary<T>): Memo<T>;