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.

Generate TypeScript object Arbitraries

See original GitHub issue

First, thanks for this magnificent library. I switched from jsVerify since couple of months ago and have already used fast-check for a couple of projects.

In my new company, we use TypeScript and I was wondering if there’s any way we can get Arbitraries from TypeScript classes without manually writing them. Say I have a class like this:

class Blog {
   id: string,
   visited: Date
}

class Author {
   id: string,
   name: string,
   blogs: [Blog]
}

How can I generate samples for Author and Blog object without writing specific arbitraries for them, instead of, e.g. something like this

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
giogonzocommented, Aug 7, 2019

Late to the party, but since io-ts has already been mentioned in this thread, here’s a quick attempt at an io-ts Codec to fast-check Arbitrary generator: https://github.com/giogonzo/fast-check-io-ts

1reaction
dubzzzcommented, Dec 15, 2018

Hi,

For the moment no 😢

I actually have the very same need but have not found any ways to do that in TypeScript for the moment. I would have wanted to provide something like: fc.forType<MyInterface>() able to generate the Arbitrary magically.

I looked into other projects that might have the same needs like https://github.com/gcanti/io-ts but they do not seem to provide such constructs. I also read stuff concerning transformers in TypeScript but it seems to be very difficult to use and add in the toolchain (even for the end-user).

So for the moment I still do not have anything for that.

Hoping to find a way to that soon ^^ Even some cli generating the Arbitrary code will do for my needs.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Typescript interface for object with arbitrary keys? [duplicate]
I want to create a type for this object in Typescript. How should I do this? javascript · typescript · Share.
Read more >
Documentation - Mapped Types - TypeScript
Generating types by re-using an existing type. ... You can map over arbitrary unions, not just unions of string | number | symbol...
Read more >
Typing objects • Tackling TypeScript - Exploring JS
Each property can have a different type. Dictionaries have an arbitrary number of properties whose names are not known at development time. All...
Read more >
Understanding and using interfaces in TypeScript
The JavaScript engines make just one shape of type TeslaModelS and each of the objects just stores corresponding values of the properties as ......
Read more >
Typing objects in TypeScript - 2ality
Dictionaries: An arbitrary amount of properties whose names are not known ... On the other hand, we can also create objects that don't...
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