stripe-node icon indicating copy to clipboard operation
stripe-node copied to clipboard

Export object interfaces from Typescript definitions

Open volkanunsal opened this issue 1 year ago • 10 comments

Is your feature request related to a problem? Please describe.

I need to be able to reference object interfaces defined inside the Stripe namespace, but I'm unable to because these interfaces aren't exported.

// File generated from our OpenAPI spec

declare module 'stripe' {
  namespace Stripe {
    /**
     * The Subscription object.
     */
    interface Subscription {

Describe the solution you'd like

Please modify your generator to add export in front of interface declarations.

// File generated from our OpenAPI spec

declare module 'stripe' {
  namespace Stripe {
    /**
     * The Subscription object.
     */
    export interface Subscription {

Describe alternatives you've considered

I currently have to copy and paste the interfaces into my app.

Additional context

No response

volkanunsal avatar Aug 05 '22 02:08 volkanunsal

Hi @volkanunsal! Thank you for your report. We are going to investigate exporting interface definitions from the d.ts files. To unblock you, could you try prefixing the interface names with Stripe namespace? This is our default export from index.d.t.s file.

const stripe = new Stripe("sk_123");

const subscriptions: Stripe.ApiList<Stripe.Subscription> = await stripe.subscriptions.list();
const subscription: Stripe.Subscription = subscriptions.data[0];
console.log(subscription.id);

kamil-stripe avatar Aug 05 '22 17:08 kamil-stripe

Strange. I tried that but it didn’t work for me.

volkanunsal avatar Aug 05 '22 19:08 volkanunsal

Are you using some compiler magic? Do I need to add something to tsconfig.json to make that work?

volkanunsal avatar Aug 05 '22 19:08 volkanunsal

Some updates. I thought it wasn't working because the types aren't populated when I start typing the type name, but I can actually use them by reference, even though intellisense doesn't know they're there. That's good enough for me.

volkanunsal avatar Aug 06 '22 00:08 volkanunsal

No compiler magic. When I tested I used this tsconfig.json. I think moduleResolution may be related to the differences in the experience.

{  
    "compilerOptions": {    
        "target": "ES2022",
        "module": "ES2022",
        "moduleResolution": "node"
    },
    "include": ["index.ts"],
    "exclude": [
        "node_modules"
    ]
}

kamil-stripe avatar Aug 08 '22 16:08 kamil-stripe

I still don't see the types in intellisense, but that's ok. It only shows exported types or classes.

Screen Shot 2022-08-08 at 9 05 29 PM

volkanunsal avatar Aug 09 '22 01:08 volkanunsal

I can't seem to use the types either. Exporting the interfaces directly seems like a no-brainer and it was most libraries do. Also, VSCode has major issues when trying to work with the entire Stripe namespace. It grinds to a halt.

ryantbrown avatar Jan 08 '23 03:01 ryantbrown

Thanks for writing in @ryantbrown and continuing to write in @volkanunsal. This is an active area of work for the team right now. in 2023. We're working on a fairly major redesign of how the library is exported/imported and as part of that we will look at this specifically and I'm re-opening the ticket accordingly.

richardm-stripe avatar Jan 09 '23 20:01 richardm-stripe

The readme says don't use import * as but it solved this issue for me.

import * as StripeAPI from 'stripe'

const Stripe = Context.Tag<StripeAPI.Stripe>('stripe')

const makeStripeLayer = (stripeAPIKey: string) =>
  Layer.succeed(
    Stripe,
    new StripeAPI.Stripe(stripeAPIKey, {
      apiVersion: '2022-11-15',
      typescript: true, // "Optionally indicate that you are using TypeScript. This currently has no runtime effect other than adding "TypeScript" to your user-agent."
    })
  )

const listPayouts = (args: StripeAPI.Stripe.PayoutListParams) =>
  Effect.flatMap(Stripe, (stripe) =>
    Effect.tryPromise(() => stripe.payouts.list(args))
  )

alex-dixon avatar Jul 20 '23 02:07 alex-dixon

Is this still in the works?

decoursin avatar May 10 '24 14:05 decoursin