diff --git a/.yarn/versions/be2c76af.yml b/.yarn/versions/be2c76af.yml new file mode 100644 index 00000000000..a9650bcd747 --- /dev/null +++ b/.yarn/versions/be2c76af.yml @@ -0,0 +1,8 @@ +releases: + fast-check: minor + +declined: + - "@fast-check/ava" + - "@fast-check/jest" + - "@fast-check/vitest" + - "@fast-check/worker" diff --git a/packages/fast-check/src/arbitrary/_internals/builders/StringifiedNatArbitraryBuilder.ts b/packages/fast-check/src/arbitrary/_internals/builders/StringifiedNatArbitraryBuilder.ts index 3109e8f6e51..8a697862c25 100644 --- a/packages/fast-check/src/arbitrary/_internals/builders/StringifiedNatArbitraryBuilder.ts +++ b/packages/fast-check/src/arbitrary/_internals/builders/StringifiedNatArbitraryBuilder.ts @@ -6,7 +6,7 @@ import { natToStringifiedNatMapper, natToStringifiedNatUnmapper } from '../mappe /** @internal */ export function buildStringifiedNatArbitrary(maxValue: number): Arbitrary { - return tuple(constantFrom<('dec' | 'oct' | 'hex')[]>('dec', 'oct', 'hex'), nat(maxValue)).map( + return tuple(constantFrom('dec', 'oct', 'hex'), nat(maxValue)).map( natToStringifiedNatMapper, natToStringifiedNatUnmapper, ); diff --git a/packages/fast-check/src/arbitrary/constantFrom.ts b/packages/fast-check/src/arbitrary/constantFrom.ts index 5c61599c648..91242ee1bd7 100644 --- a/packages/fast-check/src/arbitrary/constantFrom.ts +++ b/packages/fast-check/src/arbitrary/constantFrom.ts @@ -16,7 +16,7 @@ type Elem = T extends any[] ? T[number] : T; * @remarks Since 0.0.12 * @public */ -function constantFrom(...values: T[]): Arbitrary; +function constantFrom(...values: T[]): Arbitrary; /** * For one `...values` values - all equiprobable diff --git a/packages/fast-check/test-types/main.ts b/packages/fast-check/test-types/main.ts index b852c5ed69e..d04fd30a3e0 100644 --- a/packages/fast-check/test-types/main.ts +++ b/packages/fast-check/test-types/main.ts @@ -87,7 +87,7 @@ expectType>()( fc.nat().chain((n) => fc.array(fc.char(), { maxLength: n })), 'Type of "chain" corresponds to the return type of the passed lambda', ); -expectType>()( +expectType>()( fc.constantFrom(1, 2, 3).chain((value) => fc.constant(value)), 'Type of "chain" corresponds to the return type of the passed lambda', ); @@ -110,13 +110,11 @@ expectType>()( ); // constantFrom arbitrary -expectType>()( - fc.constantFrom(1, 2), - 'By default, "constantFrom" simplifies the type (eg.: "1 -> number")', -); +expectType>()(fc.constantFrom(1, 2), 'By default, "constantFrom" preserves the precise type'); +expectType>()(fc.constantFrom(1, 2), 'But it also accepts to receive the type'); expectType>()( fc.constantFrom(...([1, 2] as const)), - '"as const" prevent extra simplification of "constantFrom"', + '"as const" was a way to prevent extra simplification of "constantFrom", it\'s now not needed anymore', ); expectType>()( fc.constantFrom(1, 2, 'hello'), @@ -124,7 +122,7 @@ expectType>()( ); expectType>()( fc.constantFrom(...([1, 2, 'hello'] as const)), - '"as const" prevent extra simplification of "constantFrom"', + '"as const" was a way to prevent extra simplification of "constantFrom"', ); // uniqueArray arbitrary