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

Support Yup ^0.32.0 #92

Merged
merged 10 commits into from
Dec 21, 2020
Merged

Support Yup ^0.32.0 #92

merged 10 commits into from
Dec 21, 2020

Conversation

jorisre
Copy link
Member

@jorisre jorisre commented Dec 13, 2020

Related to #86 & #91

Yup@0.32.0 add Typescript support. @types/yup isn't required anymore.

@jorisre jorisre changed the title Update yup Support Yup ^0.32.X Dec 13, 2020
@jorisre jorisre requested a review from bluebill1049 December 19, 2020 23:07
import Yup from 'yup';

/**
* From 0.32.0, Yup add TypeScript support and `path` typing is optional that's why we have `@ts-expect-error`
Copy link
Member Author

Choose a reason for hiding this comment

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

@bluebill1049 I'm not satisfied, if you've a better solution

Copy link
Member

Choose a reason for hiding this comment

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

FYI: path: a string, indicating where there error was thrown. path is empty at the root level.

what do you mean by that?

Copy link
Member

Choose a reason for hiding this comment

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

Sorry, I haven't played with the latest Yup, probably lack of context.

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

oh, path is empty, basically means the object key is actually the path?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, the new type for ValidationError is:

export default class ValidationError extends Error {
    value: any;
    path?: string;
    type?: string;
    errors: string[];
    params?: Params;
    inner: ValidationError[];
    static formatError(message: string | ((params: Params) => string) | unknown, params: Params): any;
    static isError(err: any): err is ValidationError;
    constructor(errorOrErrors: string | ValidationError | ValidationError[], value?: any, field?: string, type?: string);
}

As you can see, path & type could be undefined

Copy link
Member

Choose a reason for hiding this comment

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

Hmm, interesting, let's go with the ignore for now 👍 it's a bit inconsistent for the rest of the schema libs.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok, PR is ready to review :)

@jorisre jorisre changed the title Support Yup ^0.32.X Support Yup ^0.32.0 Dec 21, 2020
@jorisre jorisre marked this pull request as ready for review December 21, 2020 07:37
@@ -42,7 +42,7 @@ const errors = {
],
};

const schema = yup.object().shape({
const schema = yup.object({
Copy link
Member

@bluebill1049 bluebill1049 Dec 21, 2020

Choose a reason for hiding this comment

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

oh, shape is gone. 👍

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.

Awesome stuff! 🥳 Thank you very much @jorisre

foo: [{ yup: true }],
createdOn: new Date('2014-09-23T19:25:25Z'),
},
values: data,
Copy link
Member

Choose a reason for hiding this comment

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

👍

expect(resolve.errors['foo'][0]['loose'].types).toMatchInlineSnapshot(`

const output = await yupResolver(schema)(
// @ts-expect-error
Copy link
Member

Choose a reason for hiding this comment

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

minor (don't have to fix it): Is this due to reuse the same schema? maybe worth to use a new schema instead?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is normal because yupResolver have a better type support now :)

The schema is good but passed data are intentionally false, that's why TS throw an error.

@@ -233,6 +244,8 @@ describe('validateWithSchema', () => {
return min ? schema.min(6) : schema;
}),
});

// @ts-expect-error
Copy link
Member

Choose a reason for hiding this comment

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

assume this is the same issue above?

@bluebill1049 bluebill1049 merged commit 39731b3 into master Dec 21, 2020
@bluebill1049 bluebill1049 deleted the update-yup branch December 29, 2020 07:50
Comment on lines +65 to +66
export const yupResolver = <T extends Yup.AnyObjectSchema>(
schema: T,
Copy link
Contributor

@sukjae sukjae Feb 26, 2021

Choose a reason for hiding this comment

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

hi!

i would like to hear about the reason why Yup.Lazy type schema is removed.
from my understanding, from #31 we begun to support Lazy type schema but was removed in this PR.

if it was meant to be, i would love hear about it.
otherwise, i would like to make PR to fix it!

thanks~ @jorisre

Copy link
Member Author

Choose a reason for hiding this comment

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

@sukjae 👋🏻
It's a mistake

Feel free to send a PR ;)

Copy link
Contributor

@sukjae sukjae Feb 26, 2021

Choose a reason for hiding this comment

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

hi @jorisre 👋
nice! i made PR #135 :)
thanks~

jorisre pushed a commit that referenced this pull request Feb 26, 2021
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.

3 participants