Skip to content

Commit

Permalink
Add type definition for Stripe.StripeResource
Browse files Browse the repository at this point in the history
  • Loading branch information
richardm-stripe committed Sep 21, 2020
1 parent 9bab8b6 commit 47463dd
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
2 changes: 2 additions & 0 deletions types/2020-08-27/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ declare module 'stripe' {

setAppInfo(info: Stripe.AppInfo): void;

StripeResource: Stripe.StripeResource;

/**
* Top Level Resources
*/
Expand Down
36 changes: 36 additions & 0 deletions types/lib.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,42 @@ import {Agent} from 'http';

declare module 'stripe' {
namespace Stripe {
export class StripeResource {
static extend<
// eslint-disable-next-line @typescript-eslint/no-explicit-any
T extends {[prop: string]: any} & {
includeBasic?: Array<
'create' | 'retrieve' | 'update' | 'list' | 'del'
>;
}
>(spec: T): StripeResource & T;
static method(spec: {
method: string;
path: string;
methodType?: 'list';
}): (...args: any[]) => object; //eslint-disable-line @typescript-eslint/no-explicit-any
static BASIC_METHODS: {
create<T>(
params: CouponCreateParams,
options?: RequestOptions
): Promise<T>;
retrieve<T>(
id: string,
params?: CouponRetrieveParams,
options?: RequestOptions
): Promise<T>;
update<T>(
id: string,
params?: CouponUpdateParams,
options?: RequestOptions
): Promise<T>;
list<T>(
params?: CouponListParams,
options?: RequestOptions
): ApiListPromise<T>;
del<T>(id: string, options?: RequestOptions): Promise<T>;
};
}
export type LatestApiVersion = '2020-08-27';
export type HttpAgent = Agent;

Expand Down
8 changes: 8 additions & 0 deletions types/test/typescriptTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,11 @@ const stripeCardError: Stripe.StripeCardError = Stripe.errors.generate({
code: 'card_declined',
charge: 'ch_123',
});

Stripe.StripeResource.extend({
includeBasic: ['retrieve'],
foo: Stripe.StripeResource.method({
method: 'create',
path: 'foo',
}),
});

0 comments on commit 47463dd

Please sign in to comment.