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

Typedef for Stripe.StripeResource #1011

Merged
merged 2 commits into from
Sep 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
37 changes: 37 additions & 0 deletions types/lib.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,43 @@ 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>;
};
static MAX_BUFFERED_REQUEST_METRICS: number;
}
export type LatestApiVersion = '2020-08-27';
export type HttpAgent = Agent;

Expand Down
11 changes: 11 additions & 0 deletions types/test/typescriptTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,14 @@ 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',
}),
});

const maxBufferedRequestMetrics: number =
Stripe.StripeResource.MAX_BUFFERED_REQUEST_METRICS;