UNPKG

2.66 kBTypeScriptView Raw
1import { Arbitrary } from '../check/arbitrary/definition/Arbitrary';
2/**
3 * Infer the type of the Arbitrary produced by {@link oneof}
4 * given the type of the source arbitraries
5 *
6 * @remarks Since 2.2.0
7 * @public
8 */
9export declare type OneOfValue<Ts extends Arbitrary<unknown>[]> = {
10 [K in keyof Ts]: Ts[K] extends Arbitrary<infer U> ? U : never;
11}[number];
12/**
13 * Constraints to be applied on {@link oneof}
14 * @remarks Since 2.14.0
15 * @public
16 */
17export declare type OneOfConstraints = {
18 /**
19 * When set to true, the shrinker of oneof will try to check if the first arbitrary
20 * could have been used to discover an issue. It allows to shrink trees.
21 *
22 * Warning: First arbitrary must be the one resulting in the smallest structures
23 * for usages in deep tree-like structures.
24 *
25 * @remarks Since 2.14.0
26 */
27 withCrossShrink?: boolean;
28 /**
29 * While going deeper and deeper within a recursive structure (see {@link letrec}),
30 * this factor will be used to increase the probability to generate instances
31 * of the first passed arbitrary.
32 *
33 * Example of values: 0.1 (small impact as depth increases), 0.5, 1 (huge impact as depth increases).
34 *
35 * @remarks Since 2.14.0
36 */
37 depthFactor?: number;
38 /**
39 * Maximal authorized depth.
40 * Once this depth has been reached only the first arbitrary will be used.
41 *
42 * @remarks Since 2.14.0
43 */
44 maxDepth?: number;
45 /**
46 * Depth identifier can be used to share the current depth between several instances.
47 *
48 * By default, if not specified, each instance of oneof will have its own depth.
49 * In other words: you can have depth=1 in one while you have depth=100 in another one.
50 *
51 * @remarks Since 2.14.0
52 */
53 depthIdentifier?: string;
54};
55/**
56 * For one of the values generated by `...arbs` - with all `...arbs` equiprobable
57 *
58 * **WARNING**: It expects at least one arbitrary
59 *
60 * @param arbs - Arbitraries that might be called to produce a value
61 *
62 * @remarks Since 0.0.1
63 * @public
64 */
65declare function oneof<Ts extends Arbitrary<unknown>[]>(...arbs: Ts): Arbitrary<OneOfValue<Ts>>;
66/**
67 * For one of the values generated by `...arbs` - with all `...arbs` equiprobable
68 *
69 * **WARNING**: It expects at least one arbitrary
70 *
71 * @param constraints - Constraints to be applied when generating the values
72 * @param arbs - Arbitraries that might be called to produce a value
73 *
74 * @remarks Since 2.14.0
75 * @public
76 */
77declare function oneof<Ts extends Arbitrary<unknown>[]>(constraints: OneOfConstraints, ...arbs: Ts): Arbitrary<OneOfValue<Ts>>;
78export { oneof };