How to chain records nicely (spreading, adding a property) / feature request for improvement
See original GitHub issue💬 Question and Help
type A = {
foo: boolean;
bar: string;
fuzz: number;
};
type B = A & {
buzz: boolean;
};
const recordA = fc.record<A>({
foo: fc.boolean(),
bar: fc.string(),
fuzz: fc.integer(),
});
const recordB: Arbitrary<B> = recordA.chain((a) =>
fc.constantFrom({
...a,
buzz: fc.boolean(),
})
);
The above gives an indication of what I am trying to achieve, but doesn’t work (due to the fact that buzz
will yield type error 'Arbitrary<boolean>' is not assignable to type 'boolean'.
I’ve solved it like this:
const recordB: Arbitrary<B> = fc
.tuple(recordA, fc.boolean())
.chain(([a, bool]) =>
fc.constantFrom({
...a,
buzz: bool,
})
);
but it doesn’t seem that pretty. I’m wondering if there is a better/recommended approach? It would be awesome if you could do something like:
const recordB: Arbitrary<B> = fc.record({ ...recordA, buzz: fc.boolean() });
Issue Analytics
- State:
- Created a year ago
- Comments:14 (4 by maintainers)
Top Results From Across the Web
How To Manage Feature Requests [Template included]
This guide will teach you everything about feature requests – how to process them, manage them, respond to them, prioritize them – so...
Read more >7 Useful Tips to Manage Feature Requests - Craft.io
Feature requests can provide product managers with great ideas for product improvement, but they must be managed correctly. Here are our top tips....
Read more >3 ways to manage software feature request - Amoeboids
Discover best practices to manage feature requests from different stakeholders. Practical tips to get you on top of the game.
Read more >The Good-Better-Best Approach to Pricing
Key steps include identifying “fence” attributes that will prevent current customers from trading down from the existing offering; carefully choosing features ...
Read more >Best Practices for EHR Implementation - Douglas County - Trilogy ...
Objective #3: Encourage continuous growth and learning among staff of the EHR system. How was practice implemented / activities To best prepare our...
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
Here is a combinator for you, hope it helps.
The pattern I’d recommend is lifting your structures from
A
toArbitrary<A>
and composing it from there, like in the intersect example.