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.
Notify
r? @richardm-stripe
Summary
This improves three friction points when working with Typescript:
new StripeResource(stripe)
now works. Prior to this change, attempting to constructStripeResource
with its one required argument would fail a type check. Support for a constructor was added in Fix StripeResource.extend type #1245 and extended in Fix StripeResource constructor type #1249 (never merged). Thanks @rattrayalex!StripeResource.extend
now returns a class that is properly typed when instantiated. Prior to this change, you could extendStripeResource
but your extensions wouldn't appear on the object after construction. Now, it does.StripeResource.method
returns a function that returnsResponse<object>
. Prior to this change, extensions created withStripeResource.method
would have a return type ofobject
. ReturningResponse<object>
makes it possible to call functions likelastResponse
without casting the value.StripeResource.method
now accepts generic type that sets the response object's type. For example, if you're hitting a customer endpoint, you can do this:StripeResource.method<Customer>(...)
. When you use that extension, it will returnResponse<Customer>
. This eliminates the need to cast when calling StripeResource extension methods.See changes to
typescriptTest.ts
for these updates in action.fixes #1249