-
Notifications
You must be signed in to change notification settings - Fork 6
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
Types not inferred in Deno / esh import #2
Comments
'm able to reproduce this on my end. The client is not being typed. @dcr-stripe any idea what might be going on here? |
Hey hey! 👋 Unfortunately @dcr-stripe isn't working at Stripe anymore so I've asked the SDK team for some insights about what the issue might be. Hopefully I'll get some answers and will get back to you! |
Hey @thorwebdev and @drewbietron, this is happening because we use "ambient module declaration" in our types for stripe-node, which Deno doesn't know how to handle. Luckily there's a workaround by using Deno's new npm module compatibility mode: import Stripe from 'npm:[email protected]';
export const stripeClient = new Stripe(
Deno.env.get("STRIPE_SECRET_KEY") as string,
{
apiVersion: "2022-11-15",
httpClient: Stripe.createFetchHttpClient(),
}
);
// stripeClient is now an instance of Stripe Also make sure you instantiate the |
thanks @paulasjes-stripe. Strange, I could have sworn that this used to work with Unfortunately Deno Deploy / Supabase does not yet support npm module compatibility 😞 |
I'm not sure if types have ever worked with
but
which is less than helpful. Unfortunately I don't think types are going to work when importing from |
Thanks @thorwebdev and @paulasjes-stripe for looking into this everyone. I also tried just using local type files and importing them using // @deno-types="../types/stripe/2022-11-15/index.d.ts" <-- copied type directory from stripe npm import here
import Stripe from "https://esm.sh/[email protected]?target=deno";
export const stripeClient = Stripe(Deno.env.get("STRIPE_SECRET_KEY"), {
apiVersion: "2022-11-15",
httpClient: Stripe.createFetchHttpClient(),
}); 'Stripe' was also declared here.
export default Stripe;
at https://esm.sh/v99/[email protected]/types/2022-11-15/index.d.ts:284:18 For a type declaration file from esh that has no types, how does it have a duplicate type? Do you think heading down this local type file is a viable path? Id be wiling to do whatever for now just to get types going in the Deno functions as its pretty hard to deal with otherwise. Thanks! |
Asked on Deno's Discord and found a workaround for now that should work while we consider switching away from ambient modules. We can explicitly tell Deno to use the available types using an import map. Create a {
"imports": {
"stripe": "https://esm.sh/[email protected]?target=deno"
}
} Then add in your {
"importMap": "./import_map.json"
} Now when importing You might need to restart Deno's language server to have it pick up the types. |
Thanks @paulasjes-stripe! |
Sadly @paulasjes-stripe `s solution also does not work for me :( |
This worked for me: import { Stripe } from "https://esm.sh/[email protected]/";
import type { Stripe as TStripe } from "https://esm.sh/v135/[email protected]/types/index.d.ts";
export const stripe: TStripe = new Stripe(
Deno.env.get("STRIPE_SECRET_API_KEY")!,
{ httpClient: Stripe.createFetchHttpClient() },
); |
The solution @paulasjes-stripe provided was working for me in v 1.46.x, but upgrading to Deno v2.0.6+ breaks the fix... |
While importing the Stripe library, the types come back as
any.
. I've tried as many combinations of esh imports for the Stripe library as I can and am at a loss. Here is what my current Deno function looks like.Any help would be appreciated.
The text was updated successfully, but these errors were encountered: