jquense / yup

Dead simple Object schema validation
MIT License
22.94k stars 935 forks source link

`InferType` does not recognize `null` as a correct type for `nullable` schemas that are also required. #2114

Closed vladflorescu closed 1 year ago

vladflorescu commented 1 year ago

InferType does not recognize null as a correct type for nullable schemas that are also required.

const schema = yup.string().nullable();
yup.InferType<typeof schema>;
// => `string`. Should be `string | null`

This issue happended previously when the types were on DefinitelyTyped, but was fixed in this PR. Looks like at some point the required behaviour was changed again here.

jquense commented 1 year ago

as of v1 required means not null and not undefined, required() will undo a nullable() call, please see: https://github.com/jquense/yup/issues/1906 and others for more info

vladflorescu commented 1 year ago

My bad, I was not aware of these changes. Sorry for the confusion and thank your for the clarifications!