question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Minor version update contains breaking TypeScript changes

See original GitHub issue

Describe 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:closed
  • Created 3 years ago
  • Reactions:5
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
pastinepolentacommented, Feb 25, 2021

The only difference is the digit that is bumped

@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 to 1.0.0 and follow the most commonly used approach to avoid issues like this in the future?

2reactions
donaldpipowitchcommented, Jan 26, 2021

every single form definition needs to be rewritten from scratch.

That is mostly correct

Hi @jquense !

Thanks for including official typescript definitions. Do you know about a migration guide? I stumbled about stuff like:

const fileSchema = object({
  fileName: string().required(),
  id: string().required(),
});

const userSchema = object({
  myFile: fileSchema.required().nullable(),
}).defined();

type UserData = InferType<typeof userSchema>;

const userData: UserData = {
  myFile: null, // null is not allowed anymore
};
Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeScript: Every minor version has breaking changes and ...
I am averse to upgrading because it's working for me and I'm concerned about 3 rounds of incompatible/breaking changes. I have no idea...
Read more >
Documentation - TypeScript 3.9
Recent versions of TypeScript (around 3.7) have had updates to the ... This is a breaking change, but we believe most code was...
Read more >
what's your process regarding breaking changes? : r/typescript
Use the breaking change doc and look at major version only. So look at 2.x -> 3.x breaking changes. Fix each manually, then...
Read more >
Semantic Versioning for TypeScript Types
Adding a new TypeScript version to the support matrix may cause breaking changes. When it does not, adding it is a normal minor...
Read more >
Announcing TypeScript 4.8 - Microsoft Developer Blogs
lib.d.ts Updates ... While TypeScript strives to avoid major breaks, even small changes in the built-in libraries can cause issues. We don't ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found