TypeScript typings for Stripe webhook events
npm install stripe-event-types

This provides TypeScript typings for Stripe webhook events to strongly type the type and data.object fields. These types are automatically generated by scraping Stripe's documentation for types of events.
Why is this needed? The typings included in the stripe library are lacking in this respect. The type for type is a string instead of a string literal and the type for data.object is {} which requires casting each usage of it. This can lead to mistakes in your implementation that could easily be caught with stronger types.
Install the package with:
``shell`
npm install stripe-event-typesor
yarn add stripe-event-types
> Note
> If you are using stripe version 13.11 or greater, you don't need the stripe-event-types library because the typings have been added to the stripe library.
| stripe-event-types version | stripe version |
| ---------------------------- | ---------------- |
| 3 | 13.5 - 13.10 |
| 2 | 11 |
| 1 | 10 |
When constructing the webhook event, cast it to Stripe.DiscriminatedEvent to strongly type the type and data.object fields:
`diff
+///
const event = stripe.webhooks.constructEvent(
request.body,
request.headers['stripe-signature'],
'whsec_test'
-);
+) as Stripe.DiscriminatedEvent;
`
The Stripe.DiscriminatedEvent.Type type is a string literal of all event types:
`ts
///
const type: Stripe.DiscriminatedEvent.Type = "charge.succeeded";
``