Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Add annotations for shopify-money gem #153
Add annotations for shopify-money gem #153
Changes from all commits
10ebac9
007a5ff
225b82f
3ae83b5
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Annoyingly,
Money::NullCurrency
is not a subclass ofMoney::Currency
, so we have to use a union.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
(*args, **_arg1, &block)
arguments are necessary to appease Sorbet, because that's the signature it generates for methods delegated viadef_delegators
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is now causing errors when
Money
instances are multiplied with integers,5 * Money.new
as the second argument isn't an Integer https://github.com/sorbet/sorbet/blob/dd4602e030832c930d0b413f31734a83708448f6/rbi/core/integer.rbi#L59.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, yeah, that's a bummer. I can't think of an easy fix though -- we'd need to be able to overload the signatures for
Integer#*
,Float#*
, etc. with an additional signature, and I think Sorbet only supports overloading for its own stdlib types.Maybe this is an acceptable limitation? It's easily fixed by swapping the arguments so that
Money#*
is called instead. It would be nice if this could be made more obvious but I'm not sure how.Open to any and all suggestions for improving this :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah we can't represent the current implementation without overloading that signature.
I'm okay with swapping the arguments solution. Only problem is it's hard to communicate this moving forward.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method always raises an exception, hence
T.noreturn
.https://github.com/Shopify/money/blob/2ebdb97174e743829542b3dafbf6cca42512d084/lib/money/money.rb#L151-L153
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't really make sense to pass non-integers to the
split
andcalculate_splits
methods IMO, but technically the gem does support it (even though it produces surprising/arguably incorrect results with non-integers).