Skip to content

Commit

Permalink
Try to type Stripe.StripeResource
Browse files Browse the repository at this point in the history
  • Loading branch information
richardm-stripe committed Sep 21, 2020
1 parent fca5659 commit 2a1aca3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
17 changes: 10 additions & 7 deletions types/lib.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,19 @@ import {Agent} from 'http';
declare module 'stripe' {
namespace Stripe {
export class StripeResource {
static extend<T>(
spec: T
): StripeResource & {
includeBasic?: Array<'create' | 'retrieve' | 'update' | 'list' | 'del'>;
} & T;
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: string;
}): (...any) => object;
methodType?: 'list';
}): (...args: any[]) => object; //eslint-disable-line @typescript-eslint/no-explicit-any
static BASIC_METHODS: {
create<T>(
params: CouponCreateParams,
Expand Down
8 changes: 7 additions & 1 deletion types/test/typescriptTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,10 @@ const stripeCardError: Stripe.StripeCardError = Stripe.errors.generate({
charge: 'ch_123',
});

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

0 comments on commit 2a1aca3

Please sign in to comment.