-
-
Notifications
You must be signed in to change notification settings - Fork 161
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
Feature/nope resolver #18
Conversation
oh wow! nice! thank you very much for this. |
This is looking great! However, I believe that this could also be put up on a website. The README is starting to be bloated with examples. I think it makes sense to include a list of examples and link them to it. |
Haven't seen any other libraries aside from the first three on the README. This kinda a great to experiment. Thank you. Really appreciated it. |
id: 'test', | ||
}, | ||
}; | ||
expect(await nopeResolver(Article)(data)).toMatchSnapshot(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you should check error value. Because I think snapshot test should be used only when comparing value is difficult.
return { | ||
...acc, | ||
...(fieldName | ||
? acc[fieldName] && validateAllFieldCriteria |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you should test here too. (the case validateAllFieldCriteria
is false)
const parseNopeSchema = (error: any, validateAllFieldCriteria: boolean) => { | ||
const errors = Object.keys(error); | ||
|
||
return Array.isArray(errors) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think errors
is always Array
type. Is it wrong?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope! This is the signature:
export interface ShapeErrors {
[key: string]: string;
}
@kysley |
import { appendErrors, transformToNestObject, Resolver } from 'react-hook-form'; | ||
import NopeObject from 'nope-validator/lib/umd/NopeObject'; | ||
|
||
const parseNopeSchema = (error: any, validateAllFieldCriteria: boolean) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this possible to avoid any?
import { ShapeErrors } from 'nope-validator/lib/umd/types';
const parseNopeSchema = (error: ShapeErrors, validateAllFieldCriteria: boolean) => {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be more complicated than casting it to ShapeErrors
, please see my comment below!
Hey guys, I'm new to using Typescript in more complex situations, and would love a little guidance here. Any Nope.string() //String, Number, Date, Boolean
.test(a => (a === '42' ? undefined : 'Must be 42'))
.validate('41');
// string => 'Must be 42' If const schema = Nope.object().shape({
name: Nope.string()
.atMost(15)
.required(),
email: Nope.string()
.email('Please provide a valid email')
.required(),
});
const errors = schema.validate({
name: 'Test',
email: 'invalidemail',
});
// ShapeErrors => { email: 'Please provide a valid email', } I think to keep consistent, we should require a |
shall we get this boy in and sort out the type afterword? ship it first :) |
There seems to be an issue with If you don't think that is critical, I'm more than happy to get this sorted out and ship it :) |
Thanks @kysley for the update, let's wait for nope validator author to response on the above :) 🙏 |
import React from 'react'; | ||
import { useForm } from 'react-hook-form'; | ||
import { nopeResolver } from '@hookform/resolvers'; | ||
import Nope from 'nope-resolver'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this import nope-validator
instead?
I would love to see this library supported, would want to replace my yup with something smaller |
use Zod instead. |
I close this one because the nope resolver is released |
Hey @bluebill1049, big fan ;)
I made this to use on a new project of mine, and figured I should put up a pr.
Let me know what you guys think!