I've installed @types/stripe-v3
and included Stripe's javascript file in a script tag in index.html
. Supposedly the Angular compiler should include all files automagically from the @types node modules. Reading up on the internet and looking at @types/stripe-v3/index.d.ts
there should be a var Stripe declared globally if the file is included by the compiler. From index.d.ts
declare var Stripe: stripe.StripeStatic;
In my service file I have the following code:
import { Injectable } from '@angular/core';
import { environment } from '../environments/environment';
@Injectable({
providedIn: 'root'
})
export class BetalingService {
stripe = Stripe(environment.stripeKey);
constructor() { }
}
Resulting in the following error:
error TS2304: Cannot find name 'Stripe'.
The issue is resolved by including a reference to the @types/stripe-v3
package in the compilerOptions.types
array of your tsconfig.app.json
file in the src
directory of your Angular project.
{
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": "../out-tsc/app",
"types": [
"stripe-v3"
]
},
"exclude": [
"test.ts",
"**/*.spec.ts"
]
}
This solution was posted by bjornharvold in this thread.