Skip to content

feat: add InferUncoerced type utility#1181

Open
ziad-saab wants to merge 3 commits intoianstormtaylor:mainfrom
ziad-saab:zs/infer-uncoerced
Open

feat: add InferUncoerced type utility#1181
ziad-saab wants to merge 3 commits intoianstormtaylor:mainfrom
ziad-saab:zs/infer-uncoerced

Conversation

@ziad-saab
Copy link

@ziad-saab ziad-saab commented May 10, 2023

Works exactly like Infer, except where part of the schema is coerced, returns the un-coerced type instead.

Works exactly like Infer, except where part of the schema is coerced,
returns the un-coerced type instead.
@ziad-saab ziad-saab force-pushed the zs/infer-uncoerced branch from c269d43 to b10c37c Compare May 10, 2023 04:26
@ziad-saab ziad-saab marked this pull request as draft May 10, 2023 04:31
@ziad-saab ziad-saab force-pushed the zs/infer-uncoerced branch from fb847ca to f8a08fe Compare May 10, 2023 19:49
- improve `InferUncoerced`: the logic to decide what the uncoerced type
is happens in the `coerce` function instead, where it should be
- improve the uncoerced type parameter in the return type of `defaulted`
@ziad-saab ziad-saab force-pushed the zs/infer-uncoerced branch from f8a08fe to 3e9dc1a Compare May 10, 2023 19:53
@ziad-saab ziad-saab marked this pull request as ready for review May 10, 2023 19:59
@amok
Copy link

amok commented Nov 2, 2023

Any chance it gets merged?

BrendanC23 added a commit to BrendanC23/resolvers that referenced this pull request Jan 28, 2026
1. Remove `/\\.` from `vitest.config.ts`. This was necessary to fix the error `No test files found`. This can also be fixed by updating Vitest to version 4, but this has a change to how snapshots are stored. See [the migration guide](https://vitest.dev/guide/migration.html#changes-to-mocking). All of the tests are found by removing `/\\.`, so the Vitest upgrade is better in a later PR.
1. Inlined `z` in `vitest.config.ts` to spy on `parse()` from `zod/v4/core`. Without this, a `TypeError: Cannot redefine property: parse` error occurs.
1. Change `bun test` to `bun run test` in CONTRIBUTING.md. `bun test` runs Bun's native test runner, not the `test` script.
1. Add `Test` stage to `.github/workflows/main.yml`. It was removed in [this PR](react-hook-form#699) and the tests haven't been running in CI.
1. Fix failing tests

Notes:

1. All
    * Fixed tests that called `useForm` outside of a component. This fixed the errors `Error: Invalid hook call. Hooks can only be called inside of the body of a function component.` and `TypeError: Cannot read properties of null (reading 'useRef')`.
1. Arktype
    * [This PR](react-hook-form#753) changed from directly calling Arktype to using standard schema. Part of this transition was changing `type: error.code` to `type: ''` (because `error.code` is not part of the standard schema). This required an update to the snapshot.
1. Superstruct
    * Fix validation of schemas that perform coercion (`{ coerce: true }` must be passed in)
    * Added additional overload for type definition `superstructResolver` that improves handling of coerced schemas (This fixes a type error with the form values).
    * Fix definition of coercion schema so that it correctly converts from number to string
    * As mentioned in [this issue](ianstormtaylor/superstruct#1159), there is no way to infer the input type of a coerced schema. A [separate PR](ianstormtaylor/superstruct#1181) would be necessary. Some of the type inference tests have been changed to manually provide the input type (this enables `watch` to return the correct value for a coerced schema).
1. Typeschema
    * The `for` loop was looping through the `schemaErrors` variable, but the current error was based on the `typeschemaErrors[0]` variable. This caused only the first error to be returned.
    * Change from spying on `typeschema.validate` to watching `schema["~standard"]`
1. Zod
    * Fixed Zod tests that spied on `schema.parse()` instead of `z4.parse()`
    * Added missing snapshots
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