There were typing issues with the return value of client.v2.core.events.list(). Codegen originally produced Stripe.V2.Event but it wasn't able to find that type, despite it being exported. Ramya manually changed the value to Event, which being in the V2 namespace already, picked the correct one. But, we wanted the codegen output to be correct.
There was also an issue with ApiListPromise. It was pulled from the V2 types so I decided to use the V1 type instead. They're very similar and users won't be interacting directly with them, we think.
What?
codegens a <reference path='../EventTypes.d.ts' /> to make V2.Events explicitly available
manually changes the shape of the relatedObject interface to not nest the data. Without that change, I had to reference relatedObject as thin_event.related_object.related_object
manually change the ThinEvent.related_object to be nullable on the push payload.
(didn't generate a diff here, but) uses V1's ApiListPromise as the list return type instead of the V2 version
Now the full codegen output works out of the box.
Testing
I was working off a local script to ensure this was free of type errors. Create a new folder and run:
npm init -y
touch index.ts
Then, paste the following into index.ts:
import { Stripe } from "stripe";
const client = new Stripe("sk_test_1234");
console.log(client);
const thinEvent = client.parseThinEvent("", "", "");
// @ts-expect-error - need to check nullability on id
thinEvent.related_object.id;
// @ts-expect-error - there shouldn't be nesting
thinEvent.related_object.related_object.id;
// this works!
thinEvent.related_object?.id;
const doWork = async () => {
const events = await client.v2.core.events.list({ object_id: "asdf" });
const e = events.data[0];
if (e.type === "v1.billing.meter.error_report_triggered") {
// related_object is populated!
console.log(e.related_object.id);
}
if (e.type === "v1.billing.meter.no_meter_found") {
// @ts-expect-error - this event has no related object
console.log(e.related_object.id);
}
};
Then, to package the SDK for use, in the local SDK checkout:
Why?
There were typing issues with the return value of
client.v2.core.events.list()
. Codegen originally producedStripe.V2.Event
but it wasn't able to find that type, despite it being exported. Ramya manually changed the value toEvent
, which being in theV2
namespace already, picked the correct one. But, we wanted the codegen output to be correct.There was also an issue with
ApiListPromise
. It was pulled from the V2 types so I decided to use the V1 type instead. They're very similar and users won't be interacting directly with them, we think.What?
<reference path='../EventTypes.d.ts' />
to makeV2.Events
explicitly availablerelatedObject
interface to not nest the data. Without that change, I had to reference relatedObject asthin_event.related_object.related_object
ThinEvent.related_object
to be nullable on the push payload.ApiListPromise
as the list return type instead of the V2 versionNow the full codegen output works out of the box.
Testing
I was working off a local script to ensure this was free of type errors. Create a new folder and run:
Then, paste the following into
index.ts
:Then, to package the SDK for use, in the local SDK checkout:
in your created folder:
(only repeat the second line if you need to check local changes)
See Also
DEVSDK-2192