fix(form-core): prioritize StandardSchemaV1 check over FieldValidateFn for callable schemas (fixes #2221)#2227
Conversation
…apFieldValidateOrFn
Arktype's `Type` implements `Callable<fn>` which makes it structurally
extend `(data: unknown) => T`. TypeScript's contravariant parameter check
means `ArkType extends FieldValidateFn<any,any,any>` evaluates to `true`
(the param check reduces to `{value:any,...} extends unknown`), so the
`StandardSchemaV1` branch was never reached and `errors` entries resolved
to `ReturnType<ArkType>` instead of `StandardSchemaV1Issue[]`.
Fix: check `StandardSchemaV1` first on both the field and form-group
branches of `UnwrapFieldValidateOrFn`. Schemas that happen to be callable
(arktype, and future StandardSchema implementations) now take the correct
path; plain function validators still fall through to the `FieldValidateFn`
branch as before.
Adds a type-level test asserting that an arktype `type('string>0')` field
validator produces `StandardSchemaV1Issue[] | undefined` errors, not the
arktype output type.
Fixes TanStack#2221
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughIn StandardSchemaV1 Type Inference Fix
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
View your CI Pipeline Execution ↗ for commit e3af80d
☁️ Nx Cloud last updated this comment at |
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2227 +/- ##
==========================================
- Coverage 90.35% 89.71% -0.64%
==========================================
Files 38 65 +27
Lines 1752 3199 +1447
Branches 444 803 +359
==========================================
+ Hits 1583 2870 +1287
- Misses 149 295 +146
- Partials 20 34 +14 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Root cause
UnwrapFieldValidateOrFncheckedFieldValidateFnbeforeStandardSchemaV1. For any callable schema (arktype, and potentially other future StandardSchema implementations), this caused the wrong branch to be taken.Arktype's
TypeusesCallable<fn extends Fn>from@ark/util, which makesTypestructurally extend its call signature(data: unknown) => TOut | ArkErrors. TypeScript's contravariant parameter check then evaluates:So the
StandardSchemaV1branch (line 457) was unreachable anderrorsresolved toReturnType<ArkType>(string | ArkErrorsfor a string schema) instead ofStandardSchemaV1Issue[].Fix
Swap the check order in both the field and form-group branches of
UnwrapFieldValidateOrFn:Plain function validators (non-schema) are unaffected — they don't implement
StandardSchemaV1so they fall through toFieldValidateFnas before.Test
Added a type-level test in
standardSchemaValidator.test-d.tsasserting that an arktypetype('string>0')field validator producesStandardSchemaV1Issue[] | undefinedforerrorMap.onChange, not an arktype output type.Fixes #2221
Summary by CodeRabbit
New Features
Bug Fixes
Tests