Skip to content

Effect Schema to Arbitrary

The Arbitrary.make function allows for the creation of random values that align with a specific Schema<A, I, R>. This function returns an Arbitrary<A> from the fast-check library, which is particularly useful for generating random test data that adheres to the defined schema constraints.

Example

1
import {
import Arbitrary
Arbitrary
,
import FastCheck
FastCheck
,
import Schema
Schema
} from "effect"
2
3
const
const Person: Schema.Struct<{ name: typeof Schema.NonEmptyString; age: Schema.filter<Schema.Schema<number, string, never>>; }>
Person
=
import Schema
Schema
.
function Struct<{ name: typeof Schema.NonEmptyString; age: Schema.filter<Schema.Schema<number, string, never>>; }>(fields: { name: typeof Schema.NonEmptyString; age: Schema.filter<Schema.Schema<number, string, never>>; }): Schema.Struct<...> (+1 overload) namespace Struct
Struct
({
4
(property) name: typeof Schema.NonEmptyString
name
:
import Schema
Schema
.
class NonEmptyString
NonEmptyString
,
5
(property) age: Schema.filter<Schema.Schema<number, string, never>>
age
:
import Schema
Schema
.
class NumberFromString

This schema transforms a `string` into a `number` by parsing the string using the `parse` function of the `effect/Number` module. It returns an error if the value can't be converted (for example when non-numeric characters are provided). The following special string values are supported: "NaN", "Infinity", "-Infinity".

NumberFromString
.
(method) Pipeable.pipe<typeof Schema.NumberFromString, Schema.filter<Schema.Schema<number, string, never>>, Schema.filter<Schema.Schema<number, string, never>>>(this: typeof Schema.NumberFromString, ab: (_: typeof Schema.NumberFromString) => Schema.filter<...>, bc: (_: Schema.filter<...>) => Schema.filter<...>): Schema.filter<...> (+21 overloads)
pipe
(
import Schema
Schema
.
const int: <number>(annotations?: Schema.Annotations.Filter<number, number> | undefined) => <I, R>(self: Schema.Schema<number, I, R>) => Schema.filter<Schema.Schema<number, I, R>>
int
(),
import Schema
Schema
.
const between: <number>(min: number, max: number, annotations?: Schema.Annotations.Filter<number, number> | undefined) => <I, R>(self: Schema.Schema<number, I, R>) => Schema.filter<...>

This filter checks whether the provided number falls within the specified minimum and maximum values.

between
(0, 200))
6
})
7
8
// This will generate an Arbitrary for the Person schema.
9
const
const PersonArbitraryType: FastCheck.Arbitrary<{ readonly name: string; readonly age: number; }>
PersonArbitraryType
=
import Arbitrary
Arbitrary
.
const make: <{ readonly name: string; readonly age: number; }, { readonly name: string; readonly age: string; }, never>(schema: Schema.Schema<{ readonly name: string; readonly age: number; }, { readonly name: string; readonly age: string; }, never>) => FastCheck.Arbitrary<...>

Returns a fast-check Arbitrary for the `A` type of the provided schema.

make
(
const Person: Schema.Struct<{ name: typeof Schema.NonEmptyString; age: Schema.filter<Schema.Schema<number, string, never>>; }>
Person
)
10
11
namespace console var console: Console

The `console` module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers. The module exports two specific components: * A `Console` class with methods such as `console.log()`, `console.error()` and `console.warn()` that can be used to write to any Node.js stream. * A global `console` instance configured to write to [`process.stdout`](https://nodejs.org/docs/latest-v22.x/api/process.html#processstdout) and [`process.stderr`](https://nodejs.org/docs/latest-v22.x/api/process.html#processstderr). The global `console` can be used without importing the `node:console` module. _**Warning**_: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the [`note on process I/O`](https://nodejs.org/docs/latest-v22.x/api/process.html#a-note-on-process-io) for more information. Example using the global `console`: ```js console.log('hello world'); // Prints: hello world, to stdout console.log('hello %s', 'world'); // Prints: hello world, to stdout console.error(new Error('Whoops, something bad happened')); // Prints error message and stack trace to stderr: // Error: Whoops, something bad happened // at [eval]:5:15 // at Script.runInThisContext (node:vm:132:18) // at Object.runInThisContext (node:vm:309:38) // at node:internal/process/execution:77:19 // at [eval]-wrapper:6:22 // at evalScript (node:internal/process/execution:76:60) // at node:internal/main/eval_string:23:3 const name = 'Will Robinson'; console.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to stderr ``` Example using the `Console` class: ```js const out = getStreamSomehow(); const err = getStreamSomehow(); const myConsole = new console.Console(out, err); myConsole.log('hello world'); // Prints: hello world, to out myConsole.log('hello %s', 'world'); // Prints: hello world, to out myConsole.error(new Error('Whoops, something bad happened')); // Prints: [Error: Whoops, something bad happened], to err const name = 'Will Robinson'; myConsole.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to err ```

console
.
(method) Console.log(message?: any, ...optionalParams: any[]): void

Prints to `stdout` with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to [`printf(3)`](http://man7.org/linux/man-pages/man3/printf.3.html) (the arguments are all passed to [`util.format()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args)). ```js const count = 5; console.log('count: %d', count); // Prints: count: 5, to stdout console.log('count:', count); // Prints: count: 5, to stdout ``` See [`util.format()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args) for more information.

log
(
import FastCheck
FastCheck
.
(alias) sample<{ readonly name: string; readonly age: number; }>(generator: FastCheck.Arbitrary<{ readonly name: string; readonly age: number; }> | FastCheck.IRawProperty<{ readonly name: string; readonly age: number; }, boolean>, params?: number | ... 1 more ... | undefined): { readonly name: string; readonly age: number; }[] export sample

Generate an array containing all the values that would have been generated during {@link assert } or {@link check }

sample
(
const PersonArbitraryType: FastCheck.Arbitrary<{ readonly name: string; readonly age: number; }>
PersonArbitraryType
, 2))
12
/*
13
Example Output:
14
[ { name: 'q r', age: 1 }, { name: '&|', age: 133 } ]
15
*/

The generation of arbitrary data requires a clear understanding of how transformations and filters are considered within a schema:

Illustrative Example

1
import {
import Arbitrary
Arbitrary
,
import FastCheck
FastCheck
,
import Schema
Schema
} from "effect"
2
3
const
const schema1: Schema.filter<Schema.Schema<string, string, never>>
schema1
=
import Schema
Schema
.
const compose: <string, string, never, string, string, never>(from: Schema.Schema<string, string, never>, to: Schema.Schema<string, string, never>) => Schema.SchemaClass<string, string, never> (+7 overloads)
compose
(
import Schema
Schema
.
class NonEmptyString
NonEmptyString
,
import Schema
Schema
.
class Trim

This schema allows removing whitespaces from the beginning and end of a string.

Trim
).
(method) Pipeable.pipe<Schema.SchemaClass<string, string, never>, Schema.filter<Schema.Schema<string, string, never>>>(this: Schema.SchemaClass<...>, ab: (_: Schema.SchemaClass<string, string, never>) => Schema.filter<...>): Schema.filter<...> (+21 overloads)
pipe
(
4
import Schema
Schema
.
const maxLength: <string>(maxLength: number, annotations?: Schema.Annotations.Filter<string, string> | undefined) => <I, R>(self: Schema.Schema<string, I, R>) => Schema.filter<...>
maxLength
(500)
5
)
6
7
// This might produce empty strings, despite the `NonEmpty` filter, due to the sequence of filters.
8
namespace console var console: Console

The `console` module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers. The module exports two specific components: * A `Console` class with methods such as `console.log()`, `console.error()` and `console.warn()` that can be used to write to any Node.js stream. * A global `console` instance configured to write to [`process.stdout`](https://nodejs.org/docs/latest-v22.x/api/process.html#processstdout) and [`process.stderr`](https://nodejs.org/docs/latest-v22.x/api/process.html#processstderr). The global `console` can be used without importing the `node:console` module. _**Warning**_: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the [`note on process I/O`](https://nodejs.org/docs/latest-v22.x/api/process.html#a-note-on-process-io) for more information. Example using the global `console`: ```js console.log('hello world'); // Prints: hello world, to stdout console.log('hello %s', 'world'); // Prints: hello world, to stdout console.error(new Error('Whoops, something bad happened')); // Prints error message and stack trace to stderr: // Error: Whoops, something bad happened // at [eval]:5:15 // at Script.runInThisContext (node:vm:132:18) // at Object.runInThisContext (node:vm:309:38) // at node:internal/process/execution:77:19 // at [eval]-wrapper:6:22 // at evalScript (node:internal/process/execution:76:60) // at node:internal/main/eval_string:23:3 const name = 'Will Robinson'; console.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to stderr ``` Example using the `Console` class: ```js const out = getStreamSomehow(); const err = getStreamSomehow(); const myConsole = new console.Console(out, err); myConsole.log('hello world'); // Prints: hello world, to out myConsole.log('hello %s', 'world'); // Prints: hello world, to out myConsole.error(new Error('Whoops, something bad happened')); // Prints: [Error: Whoops, something bad happened], to err const name = 'Will Robinson'; myConsole.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to err ```

console
.
(method) Console.log(message?: any, ...optionalParams: any[]): void

Prints to `stdout` with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to [`printf(3)`](http://man7.org/linux/man-pages/man3/printf.3.html) (the arguments are all passed to [`util.format()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args)). ```js const count = 5; console.log('count: %d', count); // Prints: count: 5, to stdout console.log('count:', count); // Prints: count: 5, to stdout ``` See [`util.format()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args) for more information.

log
(
import FastCheck
FastCheck
.
(alias) sample<string>(generator: FastCheck.Arbitrary<string> | FastCheck.IRawProperty<string, boolean>, params?: number | FastCheck.Parameters<string> | undefined): string[] export sample

Generate an array containing all the values that would have been generated during {@link assert } or {@link check }

sample
(
import Arbitrary
Arbitrary
.
const make: <string, string, never>(schema: Schema.Schema<string, string, never>) => FastCheck.Arbitrary<string>

Returns a fast-check Arbitrary for the `A` type of the provided schema.

make
(
const schema1: Schema.filter<Schema.Schema<string, string, never>>
schema1
), 2))
9
/*
10
Example Output:
11
[ '', '"Ry' ]
12
*/
13
14
const
const schema2: Schema.filter<Schema.Schema<string, string, never>>
schema2
=
import Schema
Schema
.
class Trim

This schema allows removing whitespaces from the beginning and end of a string.

Trim
.
(method) Pipeable.pipe<typeof Schema.Trim, Schema.filter<Schema.Schema<string, string, never>>, Schema.filter<Schema.Schema<string, string, never>>>(this: typeof Schema.Trim, ab: (_: typeof Schema.Trim) => Schema.filter<...>, bc: (_: Schema.filter<...>) => Schema.filter<...>): Schema.filter<...> (+21 overloads)
pipe
(
15
import Schema
Schema
.
const nonEmptyString: <string>(annotations?: Schema.Annotations.Filter<string, string> | undefined) => <I, R>(self: Schema.Schema<string, I, R>) => Schema.filter<Schema.Schema<string, I, R>>
nonEmptyString
(),
16
import Schema
Schema
.
const maxLength: <string>(maxLength: number, annotations?: Schema.Annotations.Filter<string, string> | undefined) => <I, R>(self: Schema.Schema<string, I, R>) => Schema.filter<...>
maxLength
(500)
17
)
18
19
// This configuration ensures no empty strings are produced, adhering to the `nonEmpty()` filter properly.
20
namespace console var console: Console

The `console` module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers. The module exports two specific components: * A `Console` class with methods such as `console.log()`, `console.error()` and `console.warn()` that can be used to write to any Node.js stream. * A global `console` instance configured to write to [`process.stdout`](https://nodejs.org/docs/latest-v22.x/api/process.html#processstdout) and [`process.stderr`](https://nodejs.org/docs/latest-v22.x/api/process.html#processstderr). The global `console` can be used without importing the `node:console` module. _**Warning**_: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the [`note on process I/O`](https://nodejs.org/docs/latest-v22.x/api/process.html#a-note-on-process-io) for more information. Example using the global `console`: ```js console.log('hello world'); // Prints: hello world, to stdout console.log('hello %s', 'world'); // Prints: hello world, to stdout console.error(new Error('Whoops, something bad happened')); // Prints error message and stack trace to stderr: // Error: Whoops, something bad happened // at [eval]:5:15 // at Script.runInThisContext (node:vm:132:18) // at Object.runInThisContext (node:vm:309:38) // at node:internal/process/execution:77:19 // at [eval]-wrapper:6:22 // at evalScript (node:internal/process/execution:76:60) // at node:internal/main/eval_string:23:3 const name = 'Will Robinson'; console.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to stderr ``` Example using the `Console` class: ```js const out = getStreamSomehow(); const err = getStreamSomehow(); const myConsole = new console.Console(out, err); myConsole.log('hello world'); // Prints: hello world, to out myConsole.log('hello %s', 'world'); // Prints: hello world, to out myConsole.error(new Error('Whoops, something bad happened')); // Prints: [Error: Whoops, something bad happened], to err const name = 'Will Robinson'; myConsole.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to err ```

console
.
(method) Console.log(message?: any, ...optionalParams: any[]): void

Prints to `stdout` with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to [`printf(3)`](http://man7.org/linux/man-pages/man3/printf.3.html) (the arguments are all passed to [`util.format()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args)). ```js const count = 5; console.log('count: %d', count); // Prints: count: 5, to stdout console.log('count:', count); // Prints: count: 5, to stdout ``` See [`util.format()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args) for more information.

log
(
import FastCheck
FastCheck
.
(alias) sample<string>(generator: FastCheck.Arbitrary<string> | FastCheck.IRawProperty<string, boolean>, params?: number | FastCheck.Parameters<string> | undefined): string[] export sample

Generate an array containing all the values that would have been generated during {@link assert } or {@link check }

sample
(
import Arbitrary
Arbitrary
.
const make: <string, string, never>(schema: Schema.Schema<string, string, never>) => FastCheck.Arbitrary<string>

Returns a fast-check Arbitrary for the `A` type of the provided schema.

make
(
const schema2: Schema.filter<Schema.Schema<string, string, never>>
schema2
), 2))
21
/*
22
Example Output:
23
[ ']H+MPXgZKz', 'SNS|waP~\\' ]
24
*/

Explanation:

  • Schema 1: Takes into account Schema.maxLength(500) since it is applied after the Schema.Trim transformation, but ignores the Schema.NonEmptyString as it precedes the transformations.
  • Schema 2: Adheres fully to all filters because they are correctly sequenced after transformations, preventing the generation of undesired data.

For effective and clear data generation, it’s advisable to organize transformations and filters methodically. A suggested pattern is:

  1. Filters for the initial type (I).
  2. Followed by transformations.
  3. And then filters for the transformed type (A).

This setup ensures that each stage of data processing is precise and well-defined.

Illustrative Example

Avoid haphazard combinations of transformations and filters:

1
import {
import Schema
Schema
} from "effect"
2
3
// Example of less optimal structuring where transformations and filters are mixed:
4
const
const schema: Schema.SchemaClass<string, string, never>
schema
=
import Schema
Schema
.
const compose: <string, string, never, string, string, never>(from: Schema.Schema<string, string, never>, to: Schema.Schema<string, string, never>) => Schema.SchemaClass<string, string, never> (+7 overloads)
compose
(
import Schema
Schema
.
class Lowercase

This schema converts a string to lowercase.

Lowercase
,
import Schema
Schema
.
class Trim

This schema allows removing whitespaces from the beginning and end of a string.

Trim
)

Prefer a structured approach by separating transformation steps from filter applications:

1
import {
import Schema
Schema
} from "effect"
2
3
// Recommended approach: Separate transformations from filters
4
const
const schema: Schema.transform<typeof Schema.String, Schema.filter<Schema.Schema<string, string, never>>>
schema
=
import Schema
Schema
.
const transform: <Schema.filter<Schema.Schema<string, string, never>>, typeof Schema.String>(from: typeof Schema.String, to: Schema.filter<Schema.Schema<string, string, never>>, options: { ...; } | { ...; }) => Schema.transform<...> (+1 overload)

Create a new `Schema` by transforming the input and output of an existing `Schema` using the provided mapping functions.

transform
(
5
import Schema
Schema
.
(alias) class String export String
String
,
6
import Schema
Schema
.
(alias) class String export String
String
.
(method) Pipeable.pipe<typeof Schema.String, Schema.filter<Schema.Schema<string, string, never>>, Schema.filter<Schema.Schema<string, string, never>>>(this: typeof Schema.String, ab: (_: typeof Schema.String) => Schema.filter<...>, bc: (_: Schema.filter<...>) => Schema.filter<...>): Schema.filter<...> (+21 overloads)
pipe
(
import Schema
Schema
.
const trimmed: <string>(annotations?: Schema.Annotations.Filter<string, string> | undefined) => <I, R>(self: Schema.Schema<string, I, R>) => Schema.filter<Schema.Schema<string, I, R>>

Verifies that a string contains no leading or trailing whitespaces. Note. This combinator does not make any transformations, it only validates. If what you were looking for was a combinator to trim strings, then check out the `trim` combinator.

trimmed
(),
import Schema
Schema
.
const lowercased: <string>(annotations?: Schema.Annotations.Filter<string, string> | undefined) => <I, R>(self: Schema.Schema<string, I, R>) => Schema.filter<Schema.Schema<string, I, R>>

Verifies that a string is lowercased.

lowercased
()),
7
{
8
(property) strict?: true
strict
: true,
9
(property) decode: (fromA: string, fromI: string) => string
decode
: (
(parameter) s: string
s
) =>
(parameter) s: string
s
.
(method) String.trim(): string

Removes the leading and trailing white space and line terminator characters from a string.

trim
().
(method) String.toLowerCase(): string

Converts all the alphabetic characters in a string to lowercase.

toLowerCase
(),
10
(property) encode: (toI: string, toA: string) => string
encode
: (
(parameter) s: string
s
) =>
(parameter) s: string
s
11
}
12
)

You can define how arbitrary data is generated by utilizing the arbitrary annotation in your schema definitions.

Example

1
import {
import Schema
Schema
} from "effect"
2
3
// Define a schema with a custom generator for natural numbers.
4
const
const schema: Schema.SchemaClass<number, number, never>
schema
=
import Schema
Schema
.
(alias) class Number export Number
Number
.
(method) Annotable<SchemaClass<number, number, never>, number, number, never>.annotations(annotations: Schema.Annotations.Schema<number, readonly []>): Schema.SchemaClass<number, number, never>

Merges a set of new annotations with existing ones, potentially overwriting any duplicates.

annotations
({
5
(property) Annotations.Schema<number, readonly []>.arbitrary?: ArbitraryAnnotation<number, readonly []>
arbitrary
: (/**typeParameters**/) => (
(parameter) fc: typeof import("/vercel/path1/node_modules/.pnpm/[email protected]/node_modules/effect/dist/dts/FastCheck")
fc
) =>
(parameter) fc: typeof import("/vercel/path1/node_modules/.pnpm/[email protected]/node_modules/effect/dist/dts/FastCheck")
fc
.
(alias) nat(): Arbitrary<number> (+2 overloads) export nat

For positive integers between 0 (included) and 2147483647 (included)

nat
()
6
})

The annotation allows access to any type parameters via the first argument (typeParameters) and the complete export of the fast-check library (fc). This setup enables you to return an Arbitrary that precisely generates the type of data desired.

Illustrative Example

1
import {
import Arbitrary
Arbitrary
,
import FastCheck
FastCheck
,
import Schema
Schema
} from "effect"
2
3
// Here, the 'positive' filter is overridden by the custom arbitrary definition
4
const
const problematic: Schema.refine<number, Schema.Schema<number, number, never>>
problematic
=
import Schema
Schema
.
(alias) class Number export Number
Number
.
(method) Pipeable.pipe<typeof Schema.Number, Schema.filter<Schema.Schema<number, number, never>>>(this: typeof Schema.Number, ab: (_: typeof Schema.Number) => Schema.filter<Schema.Schema<number, number, never>>): Schema.filter<...> (+21 overloads)
pipe
(
import Schema
Schema
.
const positive: <number>(annotations?: Schema.Annotations.Filter<number, number> | undefined) => <I, R>(self: Schema.Schema<number, I, R>) => Schema.filter<Schema.Schema<number, I, R>>
positive
()).
(method) Annotable<refine<number, Schema<number, number, never>>, number, number, never>.annotations(annotations: Schema.Annotations.Schema<number, readonly []>): Schema.refine<number, Schema.Schema<number, number, never>>

Merges a set of new annotations with existing ones, potentially overwriting any duplicates.

annotations
({
5
(property) Annotations.Schema<number, readonly []>.arbitrary?: Arbitrary.ArbitraryAnnotation<number, readonly []>
arbitrary
: () => (
(parameter) fc: typeof FastCheck
fc
) =>
(parameter) fc: typeof FastCheck
fc
.
(alias) integer(constraints?: FastCheck.IntegerConstraints): FastCheck.Arbitrary<number> export integer

For integers between min (included) and max (included)

integer
()
6
})
7
8
namespace console var console: Console

The `console` module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers. The module exports two specific components: * A `Console` class with methods such as `console.log()`, `console.error()` and `console.warn()` that can be used to write to any Node.js stream. * A global `console` instance configured to write to [`process.stdout`](https://nodejs.org/docs/latest-v22.x/api/process.html#processstdout) and [`process.stderr`](https://nodejs.org/docs/latest-v22.x/api/process.html#processstderr). The global `console` can be used without importing the `node:console` module. _**Warning**_: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the [`note on process I/O`](https://nodejs.org/docs/latest-v22.x/api/process.html#a-note-on-process-io) for more information. Example using the global `console`: ```js console.log('hello world'); // Prints: hello world, to stdout console.log('hello %s', 'world'); // Prints: hello world, to stdout console.error(new Error('Whoops, something bad happened')); // Prints error message and stack trace to stderr: // Error: Whoops, something bad happened // at [eval]:5:15 // at Script.runInThisContext (node:vm:132:18) // at Object.runInThisContext (node:vm:309:38) // at node:internal/process/execution:77:19 // at [eval]-wrapper:6:22 // at evalScript (node:internal/process/execution:76:60) // at node:internal/main/eval_string:23:3 const name = 'Will Robinson'; console.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to stderr ``` Example using the `Console` class: ```js const out = getStreamSomehow(); const err = getStreamSomehow(); const myConsole = new console.Console(out, err); myConsole.log('hello world'); // Prints: hello world, to out myConsole.log('hello %s', 'world'); // Prints: hello world, to out myConsole.error(new Error('Whoops, something bad happened')); // Prints: [Error: Whoops, something bad happened], to err const name = 'Will Robinson'; myConsole.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to err ```

console
.
(method) Console.log(message?: any, ...optionalParams: any[]): void

Prints to `stdout` with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to [`printf(3)`](http://man7.org/linux/man-pages/man3/printf.3.html) (the arguments are all passed to [`util.format()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args)). ```js const count = 5; console.log('count: %d', count); // Prints: count: 5, to stdout console.log('count:', count); // Prints: count: 5, to stdout ``` See [`util.format()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args) for more information.

log
(
import FastCheck
FastCheck
.
(alias) sample<number>(generator: FastCheck.Arbitrary<number> | FastCheck.IRawProperty<number, boolean>, params?: number | FastCheck.Parameters<number> | undefined): number[] export sample

Generate an array containing all the values that would have been generated during {@link assert } or {@link check }

sample
(
import Arbitrary
Arbitrary
.
const make: <number, number, never>(schema: Schema.Schema<number, number, never>) => FastCheck.Arbitrary<number>

Returns a fast-check Arbitrary for the `A` type of the provided schema.

make
(
const problematic: Schema.refine<number, Schema.Schema<number, number, never>>
problematic
), 2))
9
/*
10
Example Output:
11
[ -1600163302, -6 ]
12
*/
13
14
// Here, the 'positive' filter is applied after the arbitrary customization, ensuring it is considered
15
const
const improved: Schema.filter<Schema.Schema<number, number, never>>
improved
=
import Schema
Schema
.
(alias) class Number export Number
Number
.
(method) Annotable<SchemaClass<number, number, never>, number, number, never>.annotations(annotations: Schema.Annotations.Schema<number, readonly []>): Schema.SchemaClass<number, number, never>

Merges a set of new annotations with existing ones, potentially overwriting any duplicates.

annotations
({
16
(property) Annotations.Schema<number, readonly []>.arbitrary?: Arbitrary.ArbitraryAnnotation<number, readonly []>
arbitrary
: () => (
(parameter) fc: typeof FastCheck
fc
) =>
(parameter) fc: typeof FastCheck
fc
.
(alias) integer(constraints?: FastCheck.IntegerConstraints): FastCheck.Arbitrary<number> export integer

For integers between min (included) and max (included)

integer
()
17
}).
(method) Pipeable.pipe<Schema.SchemaClass<number, number, never>, Schema.filter<Schema.Schema<number, number, never>>>(this: Schema.SchemaClass<...>, ab: (_: Schema.SchemaClass<number, number, never>) => Schema.filter<...>): Schema.filter<...> (+21 overloads)
pipe
(
import Schema
Schema
.
const positive: <number>(annotations?: Schema.Annotations.Filter<number, number> | undefined) => <I, R>(self: Schema.Schema<number, I, R>) => Schema.filter<Schema.Schema<number, I, R>>
positive
())
18
19
namespace console var console: Console

The `console` module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers. The module exports two specific components: * A `Console` class with methods such as `console.log()`, `console.error()` and `console.warn()` that can be used to write to any Node.js stream. * A global `console` instance configured to write to [`process.stdout`](https://nodejs.org/docs/latest-v22.x/api/process.html#processstdout) and [`process.stderr`](https://nodejs.org/docs/latest-v22.x/api/process.html#processstderr). The global `console` can be used without importing the `node:console` module. _**Warning**_: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the [`note on process I/O`](https://nodejs.org/docs/latest-v22.x/api/process.html#a-note-on-process-io) for more information. Example using the global `console`: ```js console.log('hello world'); // Prints: hello world, to stdout console.log('hello %s', 'world'); // Prints: hello world, to stdout console.error(new Error('Whoops, something bad happened')); // Prints error message and stack trace to stderr: // Error: Whoops, something bad happened // at [eval]:5:15 // at Script.runInThisContext (node:vm:132:18) // at Object.runInThisContext (node:vm:309:38) // at node:internal/process/execution:77:19 // at [eval]-wrapper:6:22 // at evalScript (node:internal/process/execution:76:60) // at node:internal/main/eval_string:23:3 const name = 'Will Robinson'; console.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to stderr ``` Example using the `Console` class: ```js const out = getStreamSomehow(); const err = getStreamSomehow(); const myConsole = new console.Console(out, err); myConsole.log('hello world'); // Prints: hello world, to out myConsole.log('hello %s', 'world'); // Prints: hello world, to out myConsole.error(new Error('Whoops, something bad happened')); // Prints: [Error: Whoops, something bad happened], to err const name = 'Will Robinson'; myConsole.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to err ```

console
.
(method) Console.log(message?: any, ...optionalParams: any[]): void

Prints to `stdout` with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to [`printf(3)`](http://man7.org/linux/man-pages/man3/printf.3.html) (the arguments are all passed to [`util.format()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args)). ```js const count = 5; console.log('count: %d', count); // Prints: count: 5, to stdout console.log('count:', count); // Prints: count: 5, to stdout ``` See [`util.format()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args) for more information.

log
(
import FastCheck
FastCheck
.
(alias) sample<number>(generator: FastCheck.Arbitrary<number> | FastCheck.IRawProperty<number, boolean>, params?: number | FastCheck.Parameters<number> | undefined): number[] export sample

Generate an array containing all the values that would have been generated during {@link assert } or {@link check }

sample
(
import Arbitrary
Arbitrary
.
const make: <number, number, never>(schema: Schema.Schema<number, number, never>) => FastCheck.Arbitrary<number>

Returns a fast-check Arbitrary for the `A` type of the provided schema.

make
(
const improved: Schema.filter<Schema.Schema<number, number, never>>
improved
), 2))
20
/*
21
Example Output:
22
[ 7, 1518247613 ]
23
*/