Minor version update contains breaking TypeScript changes
See original GitHub issueDescribe the bug
Attempting to update from 0.30.0
to 0.32.8
completely crashes a TypeScript project to the point where it appears every single form definition needs to be rewritten from scratch.
To Reproduce
It’s hard to create a simple, reproducible case, though I might attempt to do that if desired. I have some custom functions for bundling validation behaviour, e.g. I have a function applying regex on string()
used to validate passwords or emails. These functions have broken response type definitions.
Further, I have form schema definitions roughly defined like this.
export const useSchema = (): ObjectSchema<FormValues> => {
return object({
foo: string().required(),
bar: string().required(),
}).defined();
};
These no longer work, either. Replacing ObjectSchema
with SchemaOf
and object({ ... })
with object().shape({ ... })
fixes the immediate errors in the file, but throws when plugged into the actual form handler. I use react-hook-form
with @hookform/resolvers/yup
.
useForm({
defaultValues: getDefaultValues(),
resolver: yupResolver(useSchema()), // this line fails to compile
});
Even if I manage to get past this issue, I run into another problem with fields that cannot be null when submitted but can be null when initialised. Image a required yes/no question which isn’t initialised to any choice. I initialise it with null
and if I try to submit, Yup should catch it if it’s not boolean
. This behaviour worked before, and maybe still works, but now TypeScript complains about incorrect types.
Lastly, I created a completely custom method on ArraySchema
. This throws in compiler, too, but I gave up on upgrading before getting to the root cause of that one.
Expected behavior
A minor version upgrade shouldn’t break so many parts of the application. If it does, there should be a clear documentation on how to upgrade to the latest version.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:5
- Comments:7 (2 by maintainers)
@jquense Chiming in since I experienced recently the same breaking changes problem between 0.30.0 and 0.31.0 on the
array().required()
and I did not imagine that it would be a breaking change. But you are right (and thanks for explaining well) about the npm versioning logic and documenting the changes on the changelog. That helped in the fix and I have learnt something new.My question is: since most of the libraries are following semver and people got used to the fact that the second number is a non-breaking change, what stops
yup
from bumping to1.0.0
and follow the most commonly used approach to avoid issues like this in the future?Hi @jquense !
Thanks for including official typescript definitions. Do you know about a migration guide? I stumbled about stuff like: