Feedback on `oneof`
See original GitHub issue💡 Idea
Currently oneof
;
- forces the user to add a type annotation at the call site
- 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:
- Created 4 years ago
- Reactions:1
- Comments:6 (5 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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 👍
Having better typings for
oneof
would definitely be a great thing.The fact to avoid users to explicitly type
<string, number>
onfc.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:
Enforcing at least one parameter with typings might break existing code (that is working today) 🙄