DavidTimms / DavidTimms/zod-fast-check

The full range of valid inputs are not produced for coerced primitives

Open
#9 0 comments 0 reactions 0 assignees View on GitHub
enhancement good first issue
Dominant language
TypeScript
Stars
130
Forks
16
PR merge metrics
No merged PRs in 30d

Description

Zod now support coerced primitive types ([see release notes](https://github.com/colinhacks/zod/releases/tag/v3.20)). For example `z.coerce.number()` will allow any input, but will convert the input to a number (or `NaN`) when it is parsed.

zod-fast-check, does produce only valid inputs and output for these schemas, but it could do a better job of generating the inputs. It currently only generates inputs which are already of the desired output type. To provide better coverage, it should also produce inputs of other types which are able to be coerced. For instance, for `z.coerce.number()`, it could produce any of the following inputs:
```ts
0, "1", true, [4], 45,6, "1e+2", new Date("Wed Feb 22 2023 21:49:17 GMT+0000")
```

Coerced types provide all of the refinement methods that their output types provide (e.g. `z.coerce.string.email()`. To retain our ability to efficiently generate these refined types, it probably makes sense to work backwards, by generating a valid output, then converting into another type, in a way which will allow it to be coerced back correctly.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.