Skip to content

Make fc.constantFrom use const generics #4047

@TomerAberbach

Description

@TomerAberbach

🚀 Feature Request

- declare function constantFrom<T = never>(...values: T[]): Arbitrary<T>;
+ declare function constantFrom<const T = never>(...values: T[]): Arbitrary<T>;

Motivation

Right now fc.constantFrom('a', 'b', 'c') returns Arbitrary<string>, which is a bit inconvenient because often the reason you are using fc.constantFrom in the first place is that you need the specific type represented by the constants. You can fix this by writing fc.constantFrom<'a' | 'b' | 'c'>('a', 'b', 'c'), but that requires duplicating the constants between the types and the values. const generics solve this problem.

Example

TS Playground

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions