#Types not importing correctly when using esm.sh

8 messages · Page 1 of 1 (latest)

tough pecan
#

I'm trying to get TypeScript types working with the stripe-node library in Deno. I've tried this:

/// <reference types="https://esm.sh/v99/stripe@11.1.0/types/2022-11-15/index.d.ts" />
import Stripe from "https://esm.sh/stripe@11.1.0?target=deno";

export const stripeClient = new Stripe(
  Deno.env.get("STRIPE_SECRET_KEY") as string,
  {
    apiVersion: "2022-11-15",
    httpClient: Stripe.createFetchHttpClient(),
  }
);

but stripeClient is still coming up with type any.

When I use npm module compatibility mode:

import Stripe from 'npm:stripe@11.1.0';

the types are automagically picked up, but unfortunately the environment I'm targeting doesn't support npm module compatibility yet.

Any way to get the types via esm.sh working as expected?

high surge
#

cc @marble bear

marble bear
#

one trick you could do is add an import map like so:

{
  "imports": {
    "stripe": "https://esm.sh/stripe@11.1.0?target=deno"
  }
}

Then update your deno.json:

{
  "importMap": "./import_map.json"
}

Then now it will work. Ideally though, Stripe should not be using an ambient module when distributing their declarations

tough pecan
#

That did the trick, thanks so much!

edgy latch
#

Hmm, I'm still encountering this issue using @marble bear 's config above, has there been a regression?

deno 1.34.3 (release, x86_64-apple-darwin) v8 11.5.150.2 typescript 5.0.4