question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feedback on `oneof`

See original GitHub issue

💡 Idea

Currently oneof;

  1. forces the user to add a type annotation at the call site
  2. doesn’t statically enforce at least one arb in input

Repros:

import * as fc from 'fast-check'

fc.oneof(fc.string(), fc.boolean()) // error
fc.oneof<string | boolean>(fc.string(), fc.boolean()) // ok
import * as fc from 'fast-check'

fc.oneof() // no error
fc.oneof(...[]) // no error

Not sure whether you may be interested (type level tricks are nice when they work, however they could add some maintenance burden) but here’s a possible solution:

import * as fc from 'fast-check'

export declare function oneof<A extends [unknown, ...Array<unknown>]>(
  ...arbs: { [K in keyof A]: fc.Arbitrary<A[K]> }
): fc.Arbitrary<A[number]>

// 1)

// const arb: fc.Arbitrary<string | boolean>
const arb = oneof(fc.string(), fc.boolean()) // ok

// 2)

oneof() // error
oneof(...[]) // error

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
dubzzzcommented, Jun 23, 2020

As I’m planning a next major of fast-check (mostly to add a full support for esm), I’ll maybe take advantage of it to include your request into it 👍

1reaction
dubzzzcommented, Feb 3, 2020

Having better typings for oneof would definitely be a great thing.

The fact to avoid users to explicitly type <string, number> on fc.oneof(fc.nat(), fc. string()) would be pretty cool.

If you want to I can let you open a PR for that purpose. Otherwise I can handle it in the future.


Concerning the idea of forcing at least one parameter at call site, it was originally the case but the constraint has been removed by https://github.com/dubzzz/fast-check/commit/1833a4b1576a4ba122146052faf9bbc987de3e1f

I’ll need to dig a little bit more to understand why. But I believe that it caused issues when combined with other arbitraries or chain:

fc.set(fc.uuid(), 1, 10)
  .chain(allUuids => fc.record({
    oneRecord: fc.oneof(...allUuids),
    records: fc.constant(allUuids),
  }))

Enforcing at least one parameter with typings might break existing code (that is working today) 🙄

Read more comments on GitHub >

github_iconTop Results From Across the Web

Read Customer Service Reviews of oneof.com - Trustpilot
We champion verified reviews. Companies can ask for reviews via automatic invitations. Labeled Verified, they're about genuine experiences. Learn more about ...
Read more >
oneof.com Reviews | check if the site is a scam or legit
It seems that oneof.com is legit and safe to use and not a scam website. The review of oneof.com is positive. The positive...
Read more >
Get a free Grammy NFT | Review of Oneof.com - YouTube
Get a free Grammy NFT | Review of Oneof.com. Watch later. Share. Copy link. Info. Shopping. Tap to unmute. If playback doesn't begin...
Read more >
OneOf (XTZ) ICO Rating, Reviews and Details | ICOholder
OneOf is a new Eco-friendly NFT platform built on the @Tezos blockchain ($XTZ) because of its energy-efficient design, specifically to create an equitable ......
Read more >
Working at OneOf - Careers & Benefits - JobSage
We're working hard to normalize employer feedback. Jobseekers deserve to know what it's truly like to work at a company, the good and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found