#lukez_checkout-typescript

1 messages ยท Page 1 of 1 (latest)

grave minnowBOT
#

๐Ÿ‘‹ 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.

lunar hazel
#

why is markdown escaped and the code not in markdown? This seems a bit unnecessary in my opinion...
-# #offtopic

mighty swan
#

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?

lunar hazel
#

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.

mighty swan
#

What do you called @types/stripe like what exactly did you install?
Our TS definitions are directly included in the stripe-node SDK

lunar hazel
mighty swan
#

๐Ÿ˜…

#

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

lunar hazel
#

ah, sorry - yes. I'm using that one you sent.

mighty swan
lunar hazel
#

I installed it with npm i stripe

#

and the types with npm i @types/stripe

#

should I maybe to to re-install it?

mighty swan
#

yeah that's likely your issue. That second command you should not have done and it likely overrode something

lunar hazel
#

oh, shiet

mighty swan
lunar hazel
#
  1. I can't simply start a fresh project ๐Ÿ˜… I will see what a complete re-install of the stripe-node package does.
  2. It is exactly like in the readme.
#

okay, I got a little update:

mighty swan
#

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

lunar hazel
# lunar hazel okay, I got a little update:
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.

mighty swan
#

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.?

lunar hazel
#

Because it says the issue occurs here:

mighty swan
#

sorry that's a picture of some internal code with no context

grave minnowBOT
lunar hazel
#

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 .

mighty swan
#

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?

lunar hazel
mighty swan
#

Cool now that makes sense. Metadata values should be strings so do isCheckout: "true" and the problem will go away

lunar hazel
#

yeah, I also thought that xD

mighty swan
#

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.

lunar hazel
lunar hazel
#

-# Noted

mighty swan
#

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

lunar hazel
#

I am about to rewrite the whole project and I also do this (key: value instead of just value) - but thank you ^^

lunar hazel
mighty swan
#

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?

lunar hazel
#

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?

mighty swan
#

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!

lunar hazel
#

oh ๐Ÿ’€

lunar hazel