Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow overrides to be used for unknown types #1

Closed
wants to merge 1 commit into from

Conversation

danieljharvey
Copy link

Hi! Hope you're well. I'm trying to work out a way of generating arbitraries for stuff like the date codec from io-ts-types, and came up with this. Is this something you'd consider?

Thanks
Dan

@giogonzo
Copy link
Owner

giogonzo commented Apr 30, 2020

Hi @danieljharvey! In fact, support for custom codec was there in the first version, I removed it here because it is inherently unsafe unless we take extreme care in defining a proper signature.

I'm not OK with throwing, but we could define two overloads as follows:

export function getArbitrary<T extends HasArbitrary>(codec: T): fc.Arbitrary<t.TypeOf<T>> {
export function getArbitrary<T extends HasArbitrary>(codec: T, overrides: Overrides): Option<fc.Arbitrary<t.TypeOf<T>>>

and return none if nothing matched.

Also the "matching" part is looks a bit brittle as defined in your PR here (i.e. not all custom codecs will have a name property). I would prefer something along the lines of:

type Overrides = Array<(input: unknown???) => Option<Arbitrary<unknown>>>

@danieljharvey
Copy link
Author

Hey! Thanks for taking a look - all sounds very sensible - will have a poke around with some of the other custom io-ts-types and see if I can come up with something that fits them all.

@danieljharvey
Copy link
Author

Closing in favour of #4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants