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

Use semver versioning #189

Closed
dylang opened this issue Mar 16, 2021 · 7 comments
Closed

Use semver versioning #189

dylang opened this issue Mar 16, 2021 · 7 comments

Comments

@dylang
Copy link

dylang commented Mar 16, 2021

Summary

In a large enterprise project, if dependencies of dependencies use type-fest, TypeScript error TS2742 can occur when mixing versions of type-fest. This seems to be rare, as this was the first time this has happened for us in many upgrades of type-fest.

If type-fest was using semver, we'd feel comfortable using ^major, for example to keep the versions in sync.

Details

So we have a dependency called @company/ui-package that has: "type-fest": "0.21.2"

Our project got a Renovate PR to upgrade our copy of type-fest:

Update dependency type-fest to v0.21.3

Which resulted in this error:

web/src/Form.styled.tsx:166:14 - error TS2742: The inferred type of 'DayOrMonthSelect' cannot be
named without a reference to '@company/ui-package/node_modules/type-fest'. This is likely not
portable. A type annotation is necessary.

166 export const DayOrMonthSelect = styled(Select)`

Workaround

We are using yarn, so we used resolutions to specify the version we want across all dependencies.

@papb
Copy link
Contributor

papb commented Mar 16, 2021

Can you clarify which version change happened in type-fest that you believed to break semver? Recall that versions starting with 0. have different semantics in semver than those starting with other numbers (such as 1. or 999.)

@brodycj
Copy link

brodycj commented Mar 16, 2021

I think the exact version change of type-fest from 0.21.2 to 0.21.3 was given in the description. But I think a reproducible example, ideally a minimal reproduction, could really help pinpoint the root cause.

@voxpelli
Copy link
Collaborator

Multiple versions of the same type definitions are a tricky beast, I believe that the Semantic Versioning of a type package has to be from the perspective of those who uses it, not that it always stays compatible with other versions of itself.

From a strict Semantic Versioning perspective though: When the major version is 0, strictly speaking any release can be breaking, though often the ecosystem still stays away from releasing breaking changes in patch releases, even though it would be allowed strictly speaking.

The way I approached your problem myself in a larger ecosystem at my previous employer was to build @hdsydsvenskan/ts-ignore-import and use it to add // @ts-ignore to such dependencies and treat such dependencies more like an optional kind of peer dependency, and only include it in the top project, which is a similar solution to yours of using resolutions.

All in all, I don't think this really is a type-fest issue but a larger issue with the type ecosystem in general.

The only thing from a Semantic Versioning perspective that type-fest could do to improve is to release a 1.0.0 and thus showing a commitment to not breaking things. I leave that up to @sindresorhus to decide (especially as I've been a bit too absent here lately)

@dylang
Copy link
Author

dylang commented Mar 17, 2021

Sorry for the confusion, my ticket was not intended to be a concern about the specific change from 0.21.2 to 0.21.3 that caused my team's project to have the error. That was just something that happened and I thought maybe could be avoided if we were using semantic versioning.

It might have been avoided in this very specific case because we'd use ^range so that Renovate would upgrade both our project's type-fest and the dependency-of-the-dependency using type-fest at the same time. We don't use ^range for packages versioned at 0.x.y.

I agree knowing "what's a major bump" can be extremely difficult for a project like this. Based on the diff, I would probably have expected a fix bump, which would have been fine in this case.

My theory is that the real culprit in the example above is TypeScript not warning us about using a type that depends on type-fest. If I'm able to make a reproducible case, I'll create an issue for TypeScript and mention this issue.

@sindresorhus
Copy link
Owner

The only thing from a Semantic Versioning perspective that type-fest could do to improve is to release a 1.0.0 and thus showing a commitment to not breaking things. I leave that up to @sindresorhus to decide (especially as I've been a bit too absent here lately)

Yeah. We can do a major release for the next release.

@papb
Copy link
Contributor

papb commented Mar 19, 2021

I am very curious for a minimal repro because I've experienced some oddities with types in the past that I believe might be related to what happened here. I want to learn this :)

@sindresorhus
Copy link
Owner

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

No branches or pull requests

5 participants