#lukez_checkout-typescript
1 messages ยท Page 1 of 1 (latest)
๐ Welcome to your new thread!
โฒ๏ธ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.
โฑ๏ธ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.
๐ This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1291544857684349129
๐ Have more to share? Add more details, code, screenshots, videos, etc. below.
why is markdown escaped and the code not in markdown? This seems a bit unnecessary in my opinion...
-# #offtopic
lukez_checkout-typescript
@lunar hazel not familiar with that error. The code you shared is definitely correct. Are you sure you are using the right type definitions?
hm
I've installed @types/stripe
however, I need to check what my buddy used
It is correct.
I also have that second error where something with the types is wrong.
When I do address = customer.deleted ? null : customer.address; it basically says that the .address property is incorrect although the type Stripe.Customer is correct.
What do you called @types/stripe like what exactly did you install?
Our TS definitions are directly included in the stripe-node SDK
I don't have stripe-node - I've installed stripe directly since I thought that this here was "stripe" and not "stripe-node":
https://github.com/fb-sean/stripe-ws/blob/ca0fa6c0e17127874ee89e421d0d79e8dbb543b9/package.json#L15
๐
We have numerous products and APIs and SDKs. Understanding what you are using exactly is what matters here. The word "stripe" could be too many things.
Are you using our stripe-node SDK? This one https://github.com/stripe/stripe-node? I think so since you are making server-side API requests
ah, sorry - yes. I'm using that one you sent.
Okay so that one has types included, you don't need to install types. Did you install a separate SDK or library such as https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/stripe-v2/index.d.ts maybe?
I installed it with npm i stripe
and the types with npm i @types/stripe
should I maybe to to re-install it?
yeah that's likely your issue. That second command you should not have done and it likely overrode something
oh, shiet
I'd remove it all, start a fresh project and just install stripe-node. Make sure to read the readme: https://github.com/stripe/stripe-node?tab=readme-ov-file#usage-with-typescript
- I can't simply start a fresh project ๐ I will see what a complete re-install of the stripe-node package does.
- It is exactly like in the readme.
okay, I got a little update:
all good, I mostly am explaining that sometimes was installed wrong and it looks possibly like a configuration issue on your laptop too. But stripe-node comes with its own types and as long as you install a recent SDK it would have that parameter properly
const session = await stripe.checkout.sessions.create({
allow_promotion_codes: true,
});
I did this and this still works. But as soon as I add the property isCheckout: true anywhere it flips me off.
what does that mean isCheckout: true? That is a Stripe API request for the Create checkout Session API https://docs.stripe.com/api/checkout/sessions/create and that doesn't have such a parameter. Can you clearly explain what you are adding, where, what error(s) you get, etc.?
Because it says the issue occurs here:
sorry that's a picture of some internal code with no context
it's from the shared.d.ts where TS says "The expected type comes from this index signature.".
In line 15 it states that MetadataParam cannot be of the type boolean, which interferes with isCheckout: true .
Please try and share real and exact code and what you do ๐
I assume you are passing isCheckout: true as a metadata key but not saying so?
oh, sorry ๐ Yes
As soon as I add isCheckout somewhere it shows me an error. Only this time, directly on the function and not somewhere else.
And the section in the types declaration is here: https://github.com/stripe/stripe-node/blob/64238dde1ea209e769ea9a2c8c78e1a5b82f30fc/types/shared.d.ts#L14
Cool now that makes sense. Metadata values should be strings so do isCheckout: "true" and the problem will go away
yeah, I also thought that xD
Also protip: unless you are sharing an error visible only in the IDE please share code as text instead of a picture if possible. Really hard to debug or help fix code from just a picture.
Additionally, should I create a new Thread for this second issue?
Okay, I just thought that an image shows it better where an error is.
-# Noted
Also personal preference, I'm old, but I hate that JS magic where you do xxxx just because the key and variable name are identical. I strongly recommend doing serverId: serverId. And then I also recommend having a clear naming scheme for your metadata keys that isn't just the variable name so something like server-id: serverId
Personal preference is obviously, what you have definitely works
and yeah the picture would have been reasonable if it contained the exact TS error you get on hover I think
I am about to rewrite the whole project and I also do this (key: value instead of just value) - but thank you ^^
Well, it's in German because my IDE is in German ๐
That wouldn't really help
yep makes sense hence the no picture in that case ๐
As for the second error it's because "deleted objects" have a different type signature as they have almost no properties. It's to avoid making every property optional
So you can see https://github.com/stripe/stripe-node/blob/master/types/Customers.d.ts#L287
and so you have to check if deleted and if it isn't you have to cast to Customer otherwise it's a union of Customer and DeletedCustomer. Does that make sense?
Okay, I did not understand everything. But I just tried something and it works somehow
This
customer.deleted === true ? null : customer.address
instead of
customer.deleted ? null : customer.address
Because customer.deleted returns void or false which is false anyway.
btw. why does .deleted return void instead of a boolean?
because that property is only present if the Customer is deleted, it's... weird and historical so not something we can easily change.
I have to run but @copper tulip is taking over if you have follow up questions!
oh ๐
Thank you, you've helped me really much ^^ cya!