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

fix(resolvers): solve valibot resolver type error #53

Merged
merged 1 commit into from
Feb 17, 2024

Conversation

Mini-ghost
Copy link
Owner

πŸ”— Linked issue

N/A

❓ Type of change

  • πŸ“– Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

Currently, if we pass RecursiveSchema from valibot to valibotResolver, there will be a type error message:

import { useForm } from '@vorms/core'
import { valibotResolver } from '@vorms/resolvers/valibot'
import { object, recursive, string } from 'valibot'

const schema = recursive(() => { 
  console.log('schema')
  return object({
    name: string(),
    email: string(),
  })
})

const { register, handleSubmit } = useForm({
  initialValues: {
    name: 'John Doe',
    email: '',
  },                                      
  validate: valibotResolver(schema),
  //                        ~~~~~~~
  onSubmit(values) {
    console.log(values)
  }
})
Argument of type 'RecursiveSchema<() => ObjectSchema<{ name: StringSchema<string>; email: StringSchema<string>; }, { name: string; email: string; }>, { name: string; email: string; }>' is not assignable to parameter of type 'ObjectSchema<any, any>'.
  Property 'object' is missing in type 'RecursiveSchema<() => ObjectSchema<{ name: StringSchema<string>; email: StringSchema<string>; }, { name: string; email: string; }>, { name: string; email: string; }>' but required in type '{ schema: "object"; object: any; }'

This PR replaces the originally expected ObjectSchema with BaseSchema | BaseSchemaAsync to resolve this issue.

πŸ“ Checklist

  • I have read the Contributing Guidelines.
  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@Mini-ghost Mini-ghost merged commit 82e6958 into main Feb 17, 2024
3 checks passed
@Mini-ghost Mini-ghost deleted the fix/solve-valibot-resolver-type branch February 17, 2024 17:08
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.

1 participant