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

Export object interfaces from Typescript definitions #1502

Open
volkanunsal opened this issue Aug 5, 2022 · 9 comments
Open

Export object interfaces from Typescript definitions #1502

volkanunsal opened this issue Aug 5, 2022 · 9 comments

Comments

@volkanunsal
Copy link

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

@kamil-stripe
Copy link
Contributor

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);

@volkanunsal
Copy link
Author

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

@volkanunsal
Copy link
Author

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

@volkanunsal
Copy link
Author

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.

@kamil-stripe
Copy link
Contributor

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"
    ]
}

@volkanunsal
Copy link
Author

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

@ryantbrown
Copy link

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.

@richardm-stripe
Copy link
Contributor

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.

@alex-dixon
Copy link

alex-dixon commented Jul 20, 2023

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))
  )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants