-
Notifications
You must be signed in to change notification settings - Fork 637
Description
Is your feature request related to a problem? Please describe.
Some .rbi type definitions for the gem are incomplete or incorrect. Here is a non-exhaustive list of issues:
-
1.
Stripe::StripeObjectincludes::Enumerable, but doing afindon aStripe::ListObject(which inherits fromStripe::StripeObject) does not narrow the type like it usually does for other enumerables likeT::Array. I think because theeachtype needs to be defined explicitly? See: https://sorbet.org/docs/stdlib-generics#implementing-the-enumerable-interface -
2. the type for a
Stripe::Eventdata.objectis incorrectly typed to only a simpleT::Hashwhich forces us to useT.cast:
Notice how the description says it is a full object as value, which is indeed the case 🤔 Should it be typed to a Stripe::StripeObjectinstead? Ideally theeventitself could be narrowed down with a generic to aStripe::Event[Stripe::PaymentIntent], for example… Thenevent.data.objectwould automatically be typed to aStripe::PaymentIntent. -
3.
Stripe::Account#external_accountsis typed as a simpleStripe::ListObject, but ideally it would be narrowed to a list ofT.any(Stripe::BankAccount, Stripe::Card), like it’s already the case in external account related operations. I wonder if again a generic would be the right solution here so that you can express what kind of objects a list contains 🤔 MaybeT.any(Stripe::BankAccount, Stripe::Card)could even be exposed as aStripe::Account::ExternalAccounttype alias? -
4.
Stripe::Account.retrievereturnsT.untypedinstead of aStripe::Account -
5.
Stripe::Account.create_login_linkreturnsT.untypedinstead of aStripe::LoginLink -
6.
Stripe::Transfer.create_reversalis wrongly typed to return aStripe::Transferobject with a nested reversal object instead of a top-levelStripe::Reversal -
7. Error types seem to be incomplete:
-
Stripe::StripeError#errorreturnsT.untypedinstead of aStripe::ErrorObject -
Stripe::ErrorObject#payment_intentreturnsT.untypedinstead of aT.nilable(Stripe::PaymentIntent)(I assume there are other objects than a payment intent); currently it actually is an instance ofStripe::StripeObject, it doesn’t get serialized to aStripe::PaymentIntent. -
Stripe::ErrorObject#codereturnsT.untypedinstead of aString
-
Also see #1579; maybe some of it has already been fixed in recent updates.
And, I don’t know if you’re aiming for full .rbi type coverage, but:
-
Stripe::Object.construct_from(e.g.Stripe::Event.construct_from(…)) isn’t typed and returnsT.untyped. I think it should returnT.selfinstead? - Similarly,
Stripe::Webhook.construct_eventisn’t typed. We have a shim for it:
module Stripe::Webhook
sig {
params(payload: String, signature_header: String, endpoint_secret: String, tolerance: T.nilable(Integer))
.returns(Stripe::Event)
}
def self.construct_event(payload, signature_header, endpoint_secret, tolerance: Stripe::Webhook::DEFAULT_TOLERANCE)
end
endAre these kind of types something you’d rather goes into https://github.com/Shopify/rbi-central/blob/main/rbi/annotations/stripe.rbi? In an ideal world, the annotations in rbi-central would not be necessary since you now ship your own type annotations.
Describe the solution you'd like
There are simple workarounds (type assertions, shims) around most of these issues, but ideally they would be fixed. Since Stripe created & maintains Sorbet, it was a bit surprising to see that the gem is not better typed! I realize some improvements have been made in recent versions, thank you for that! :)
I think the rbi-central topic is also something you should look at, it’s confusing that some types are maintained there instead of directly contributed into this gem’s .rbi file.
Describe alternatives you've considered
No response
Additional context
No response