Generate TypeScript object Arbitraries
See original GitHub issueFirst, 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:
- Created 5 years ago
- Reactions:3
- Comments:5 (4 by maintainers)
Top 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 >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
Late to the party, but since
io-ts
has already been mentioned in this thread, here’s a quick attempt at anio-ts
Codec tofast-check
Arbitrary generator: https://github.com/giogonzo/fast-check-io-tsHi,
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 theArbitrary
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.