-
Notifications
You must be signed in to change notification settings - Fork 935
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
How do I migrate to v1 #1906
Comments
Hi, I found nothing about 'BaseSchema' from 'yup', it disapears in v1 ? We can replace it by something else ? Ok, I found "Schema" instead of "BaseSchema", are you agree ? Regards, |
Yes it's just Schema now |
Hi, We've switched to yup v1, and it seems to have broken the type imports since lib doesn't exist any longer. For v1 how should we go about accessing the types like MessageParams and ConditionOptions? They seem to be in the yup index.d.ts file, but don't seem to be exported in the yup module, so I'm unsure about how to access the types with v1. |
If you need more types exported open an issue (or better a PR) |
We previously had this code: What was |
Hey guys, I was using |
Just |
Hi, i am updating my project, I was using |
@ImraKocis that is answered in the last section of the first message |
It's |
sorry I still don't understand: |
__inputType doesn't exist anymore, the concept was removed. It's explained a little more in depthin the the issue you linked |
Could you please add #2058 (comment) to this migration guide? Thanks |
So update Yup's section of the Zod comparison accordingly. See: jquense/yup#1906
) So update Yup's section of the Zod comparison accordingly. See: jquense/yup#1906
Hi, I was extending --EDIT-- import * as yup from 'yup';
export type Reference<TValue = unknown> = ReturnType<(typeof yup.ref<TValue>)>; |
How do I migrate when const steppedDurationSchema = object().shape({
initialDuration: string().required(REQUIRED),
subsequentStepsDuration: string().required(REQUIRED),
maximumDuration: string(),
stepUnit: string().required(REQUIRED)
});
const optionalSteppedDurationSchema = object().shape({
initialDuration: string().nullable(),
subsequentStepsDuration: string().nullable(),
maximumDuration: string().nullable(),
stepUnit: string().nullable()
});
…
steppedDuration: object().when(['usageEnds', 'endOfTripDurationType'], {
is: (usageEnds: UsageEnd[], endOfTripDurationType?: string) =>
usageEnds.includes(UsageEnd.STANDARD_DURATION) &&
endOfTripDurationType === 'STEPPED_DURATION',
then: steppedDurationSchema,
otherwise: optionalSteppedDurationSchema
})
… |
Solved, I had to move the definitions to inline.. …
steppedDuration: object().when(['usageEnds', 'endOfTripDurationType'], {
is: (usageEnds: UsageEnd[], endOfTripDurationType?: string) =>
usageEnds.includes(UsageEnd.STANDARD_DURATION) &&
endOfTripDurationType === 'STEPPED_DURATION',
then: (schema) =>
schema.shape({
initialDuration: string().required(REQUIRED),
subsequentStepsDuration: string().required(REQUIRED),
maximumDuration: string(),
stepUnit: string().required(REQUIRED)
}),
otherwise: (schema) =>
schema.shape({
initialDuration: string().nullable(),
subsequentStepsDuration: string().nullable(),
maximumDuration: string().nullable(),
stepUnit: string().nullable()
})
})
… |
Is there a plan to prepare normal migration document, with the list of all deprecated items and what should be updated. |
How do you migrate export const ValidationSchema = object().shape({
field: mixed().when('something', {
is: false,
then: string().label('Field').required(),
}),
}); I've migrated places with is it ok to just replace
with
? |
Breaking change: when throwing a "required" validation error it's no longer Lines 679 to 689 in 5a22c16
Lines 691 to 701 in 5a22c16
|
Also notice that |
Please read through the releases: https://github.com/jquense/yup/releases which document the breaking changes in more detail but the tl;dr; here is the following:
Big additions
The
tuple
type, objectomit
,pick
,partial
anddeepPartial
better TS support, most consistent behavior andBreaking Changes
Flat bundle
There is no distributed
lib
folder anymore everything is bundled into one file with rollupStricter
when
API#1542
tl;dr; use functions for then/otherwise conditions. convert
.when({ to: true, then: yup.string().required() })
to.when({ to: true, then: schema => schema.required() })
Email validation is looser
Email validation via a regexp is impossible to do 100% correctly rather than try to match every case yup now matches the WHATWG definition of a valid email address to align with how browsers validate (or are supposed to validate) email inputs since that is a common use case.
Nullability and optionality are stricter and enforced during
cast
This is the largest, and likely most disruptive change. Prior yup allowed for patterns like:
This may seem unintuitive behavior (and it is) but allowed for a common client side validation case, where we want to use a single schema to parse server data, as well as validate user input. In other words, a server might return invalid "default" values that should still fail when trying to submit.
Now,
nullable()
,defined
andrequired
are all mutually dependent methods. Meaningstring().nullable().defined().required()
produces a schema where the value must be a string, and not null or undefined. The effect of this is that the type of a cast() is now accurate and the same as the type returned from validate.There is a migration path for folks who use this pattern:
name.cast(null, { assert: 'ignore-optionality'}) // => null
read more hereThere are some knock-on changes caused by this as well, due to internals changing. Specifically
describe()
now returnsoptional
andnullable
properties instead ofrequired
to distinguish between the two possible states clearly. There is also no longer a test namerequired
for most schema:TS generics are faster, more accurate and very different from v032.
SchemaOf<Person>
has been removed, and you can now provide the type you want the schema to match:ObjectSchema<Person>
. read more: hereThe text was updated successfully, but these errors were encountered: