Skip to content

feat: implement typed Input/Output interface for resolvers#753

Merged
jorisre merged 30 commits intodevfrom
fix/743
Mar 31, 2025
Merged

feat: implement typed Input/Output interface for resolvers#753
jorisre merged 30 commits intodevfrom
fix/743

Conversation

@jorisre
Copy link
Member

@jorisre jorisre commented Feb 26, 2025

This PR implements typed Input/Output interfaces for resolvers, which needs react-hook-form/react-hook-form#12638

Next steps will involve extending this implementation to all applicable resolver modules.

Note: This PR will fail until the release of react-hook-form/react-hook-form#12638

Fixes #743

@controversial
Copy link

controversial commented Mar 6, 2025

@jorisre I believe I made some progress on the types here, in #755 and in react-hook-form/react-hook-form#12664

Let me know how it looks to you

@github-actions
Copy link
Contributor

github-actions bot commented Mar 27, 2025

Size Change: +1.72 kB (+3.17%)

Total Size: 55.8 kB

Filename Size Change
arktype/dist/arktype.js 675 B +310 B (+84.93%) 🆘
arktype/dist/arktype.mjs 687 B +308 B (+81.27%) 🆘
arktype/dist/arktype.modern.mjs 628 B +262 B (+71.58%) 🆘
arktype/dist/arktype.module.js 687 B +308 B (+81.27%) 🆘
arktype/dist/arktype.umd.js 756 B +293 B (+63.28%) 🆘
standard-schema/dist/standard-schema.js 609 B +2 B (+0.33%)
standard-schema/dist/standard-schema.mjs 627 B +2 B (+0.32%)
standard-schema/dist/standard-schema.modern.mjs 570 B +2 B (+0.35%)
standard-schema/dist/standard-schema.module.js 627 B +2 B (+0.32%)
standard-schema/dist/standard-schema.umd.js 708 B +3 B (+0.43%)
typeschema/dist/typeschema.js 526 B +47 B (+9.81%) ⚠️
typeschema/dist/typeschema.mjs 542 B +51 B (+10.39%) ⚠️
typeschema/dist/typeschema.modern.mjs 492 B +32 B (+6.96%) 🔍
typeschema/dist/typeschema.module.js 542 B +51 B (+10.39%) ⚠️
typeschema/dist/typeschema.umd.js 630 B +44 B (+7.51%) 🔍
yup/dist/yup.mjs 639 B -2 B (-0.31%)
yup/dist/yup.modern.mjs 579 B +5 B (+0.87%)
yup/dist/yup.module.js 639 B -2 B (-0.31%)
yup/dist/yup.umd.js 728 B -2 B (-0.27%)
ℹ️ View Unchanged
Filename Size
ajv/dist/ajv.js 692 B
ajv/dist/ajv.mjs 646 B
ajv/dist/ajv.modern.mjs 604 B
ajv/dist/ajv.module.js 646 B
ajv/dist/ajv.umd.js 803 B
class-validator/dist/class-validator.js 538 B
class-validator/dist/class-validator.mjs 559 B
class-validator/dist/class-validator.modern.mjs 511 B
class-validator/dist/class-validator.module.js 559 B
class-validator/dist/class-validator.umd.js 637 B
computed-types/dist/computed-types.js 385 B
computed-types/dist/computed-types.mjs 400 B
computed-types/dist/computed-types.modern.mjs 340 B
computed-types/dist/computed-types.module.js 400 B
computed-types/dist/computed-types.umd.js 476 B
dist/resolvers.js 444 B
dist/resolvers.mjs 454 B
dist/resolvers.module.js 454 B
dist/resolvers.umd.js 538 B
effect-ts/dist/effect-ts.js 536 B
effect-ts/dist/effect-ts.mjs 554 B
effect-ts/dist/effect-ts.modern.mjs 537 B
effect-ts/dist/effect-ts.module.js 554 B
effect-ts/dist/effect-ts.umd.js 652 B
fluentvalidation-ts/dist/fluentvalidation-ts.js 487 B
fluentvalidation-ts/dist/fluentvalidation-ts.mjs 505 B
fluentvalidation-ts/dist/fluentvalidation-ts.modern.mjs 434 B
fluentvalidation-ts/dist/fluentvalidation-ts.module.js 505 B
fluentvalidation-ts/dist/fluentvalidation-ts.umd.js 575 B
io-ts/dist/io-ts.js 1.27 kB
io-ts/dist/io-ts.mjs 1.15 kB
io-ts/dist/io-ts.modern.mjs 1.12 kB
io-ts/dist/io-ts.module.js 1.15 kB
io-ts/dist/io-ts.umd.js 1.39 kB
joi/dist/joi.js 590 B
joi/dist/joi.mjs 606 B
joi/dist/joi.modern.mjs 490 B
joi/dist/joi.module.js 606 B
joi/dist/joi.umd.js 694 B
nope/dist/nope.js 346 B
nope/dist/nope.mjs 363 B
nope/dist/nope.modern.mjs 330 B
nope/dist/nope.module.js 363 B
nope/dist/nope.umd.js 432 B
superstruct/dist/superstruct.js 339 B
superstruct/dist/superstruct.mjs 353 B
superstruct/dist/superstruct.modern.mjs 342 B
superstruct/dist/superstruct.module.js 353 B
superstruct/dist/superstruct.umd.js 437 B
typanion/dist/typanion.js 329 B
typanion/dist/typanion.mjs 345 B
typanion/dist/typanion.modern.mjs 325 B
typanion/dist/typanion.module.js 345 B
typanion/dist/typanion.umd.js 425 B
typebox/dist/typebox.js 501 B
typebox/dist/typebox.mjs 517 B
typebox/dist/typebox.modern.mjs 494 B
typebox/dist/typebox.module.js 517 B
typebox/dist/typebox.umd.js 618 B
valibot/dist/valibot.js 477 B
valibot/dist/valibot.mjs 492 B
valibot/dist/valibot.modern.mjs 452 B
valibot/dist/valibot.module.js 492 B
valibot/dist/valibot.umd.js 586 B
vest/dist/vest.js 479 B
vest/dist/vest.mjs 443 B
vest/dist/vest.modern.mjs 390 B
vest/dist/vest.module.js 443 B
vest/dist/vest.umd.js 568 B
vine/dist/vine.js 543 B
vine/dist/vine.mjs 553 B
vine/dist/vine.modern.mjs 484 B
vine/dist/vine.module.js 553 B
vine/dist/vine.umd.js 650 B
yup/dist/yup.js 626 B
zod/dist/zod.js 611 B
zod/dist/zod.mjs 629 B
zod/dist/zod.modern.mjs 565 B
zod/dist/zod.module.js 629 B
zod/dist/zod.umd.js 717 B

compressed-size-action

@jorisre jorisre marked this pull request as ready for review March 27, 2025 11:46
kotarella1110
kotarella1110 previously approved these changes Mar 27, 2025
Copy link
Member

@kotarella1110 kotarella1110 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Appreciate your hard work!

@jorisre
Copy link
Member Author

jorisre commented Mar 27, 2025

LGTM! Appreciate your hard work!

Appreciate your help, thanks again!

Copy link
Member

@bluebill1049 bluebill1049 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks everyone! Huge effort @jorisre

bluebill1049
bluebill1049 previously approved these changes Mar 31, 2025
@jorisre jorisre changed the base branch from dev to master March 31, 2025 13:03
@jorisre jorisre dismissed stale reviews from bluebill1049 and kotarella1110 March 31, 2025 13:03

The base branch was changed.

@jorisre jorisre changed the base branch from master to dev March 31, 2025 13:03
@jorisre jorisre merged commit 6124c59 into dev Mar 31, 2025
4 checks passed
@jorisre jorisre deleted the fix/743 branch March 31, 2025 13:04
@github-actions
Copy link
Contributor

github-actions bot commented Apr 1, 2025

🎉 This PR is included in version 5.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

"license": "MIT",
"peerDependencies": {
"react-hook-form": "^7.0.0",
"react-hook-form": "7.55.0",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be locked to version 7.55.0?

Suggested change
"react-hook-form": "7.55.0",
"react-hook-form": "^7.55.0",

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch @spiftire

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we switch from arktype native implementation to standard-schema? And why not all standard-schema-compatible resolvers follow this approach?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, using this approach will lead to the resolver failing to infer the type from the schema, unless the user specifically installs @standard-schema/spec as their dependency

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

apologize for mentioning you guys @jorisre @bluebill1049 @kotarella1110

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We switched to standard-schema from the native arktype implementation because type inference in Arktype wasn't working as expected. But if you've found a solid solution, we're happy to review a PR :)

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Zod resolver infered types are incorect since 4.1.0

6 participants