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

Unintuitive comparison result for lt(undefined, B) #67

Open
dfunckt opened this issue Nov 5, 2018 · 1 comment
Open

Unintuitive comparison result for lt(undefined, B) #67

dfunckt opened this issue Nov 5, 2018 · 1 comment

Comments

@dfunckt
Copy link

dfunckt commented Nov 5, 2018

lt(undefined, B) results in true and it seems that's expected: https://github.com/balena-io-modules/resin-semver/blob/master/test/index.spec.ts#L448

However I think the result is counter-intuitive and should really be false -- i.e. undefined should always result in false.

The current behaviour prevents writing code that only branches to handle legacy cases, eg.:

if (semver.lt(osVersion, '2.0.0')) {
  return doLegacy();
}
return doNormal();

The above must be written with the "happy path" inverted or check for undefined in the branch condition.

@dfunckt
Copy link
Author

dfunckt commented Nov 5, 2018

Even more counter-intuitive is that satisfies seems to work as expected: https://github.com/balena-io-modules/resin-semver/blob/master/test/index.spec.ts#L505

So the above could be written:

if (semver.satisfies(osVersion, '<2.0.0')) {
  return doLegacy();
}
return doNormal();

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

1 participant