I'm trying to create an application using loopback framework, which uses typescript. I want to use Stripe, and I installed both stripe and @types/stripe, because from what I understand, Typescript needs definite types.
I'm importing stripe as import * as stripe from 'stripe'
and I want to import the types as well so I'm doing import * as Stripe from '@types/stripe'
However, I'm getting the error: Cannot import type declaration files. Consider importing 'stripe' instead of '@types/stripe'
How can I import the types so that I can use them to declare function returns, etc?
If you're using stripe-node
[1] directly, it now supports typescript and has types defined. For those who find this and are using the types from stripe-node, you can import Stripe like the following:
import Stripe from 'stripe';
const stripe = new Stripe(
'sk_test_...',
{
apiVersion: '2019-12-03',
typescript: true,
}
);
[1] https://github.com/stripe/stripe-node#usage-with-typescript
You did correctly by installing stripe and @types/stripe. But, you don't need to import types declaration in the source file
import * as Stripe from 'stripe';
export const stripe = new Stripe('whateverkey');
function createHeader(): Stripe.HeaderOptions { // use stripe types for return type
return 'stripe header';
}
if you use VSCode or IDE editor, it should give you IntelliSense such as below
Hope it helps
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With