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.

Arbitrary records with optional fields

See original GitHub issue

💬 Question and Help

Hi, I have an interface with optional fields, something like:

interface Foo {
  bar?: number
}

I am trying to generate arbitraries for this, but fc.option(fc.integer()) doesn’t seem to do the trick, since it always includes the property (typed as number | null). I’d like to omit the property entirely as optional, but I believe I can settle for number | undefined.

What’s the best way to do this?

Thanks!

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
gnidancommented, Apr 18, 2021

Thank you @dubzzz! I just ran into this situation again and was quite surprised to see that past-me opened this issue over a year ago! And that you fixed it!

1reaction
dubzzzcommented, Jan 8, 2021

@gnidan The feature is now native in fast-check 2.11.0 🥳

Look for record and requiredKeys in https://github.com/dubzzz/fast-check/blob/master/documentation/Arbitraries.md#object

Read more comments on GitHub >

github_iconTop Results From Across the Web

defrecord with optional keys - clojure - Stack Overflow
Since records in Clojure implement the map interface, all fields except for the ones specified in the constructor are optional. So, declaring your...
Read more >
Creating a table with many optional fields
This schema only has 3 tables (not "tons") and you can have as many contact types as you want. The joins aren't that...
Read more >
Less verbose records with optional values · Issue #382 - GitHub
For example, suppose that a user is interested in the default value for one of the non-required fields. If you represent the defaultable...
Read more >
Limitations of OCAML records
Idea: add the concept of model for the fields that are not explicitely mentioned in the record type: • ∂Abs to say that...
Read more >
Table - Airtable Scripting
Table. Table represents each table in your base. You can use it to find all of the views, fields, and records it contains....
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