Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Helper method to get item ids #1793

Open
nathanhleung opened this issue May 18, 2023 · 2 comments
Open

Helper method to get item ids #1793

nathanhleung opened this issue May 18, 2023 · 2 comments

Comments

@nathanhleung
Copy link

nathanhleung commented May 18, 2023

Is your feature request related to a problem? Please describe.

I'm often writing the same TypeScript code to narrow the types returned by the API to extract item IDs. Example:

const price = await stripe.prices.retrieve(priceId);
const { product } = price;

// this part
const productId = (typeof product === 'string' ? product : product.id);

Describe the solution you'd like

It would be nice if this library included a helper method for this, e.g.

function getId(stripeObject: { id: string } | string) {
  return typeof stripeObject === 'string' ? stripeObject : stripeObject.id;
}

Then I could write

const price = await stripe.prices.retrieve(priceId);
const { product } = price;

const productId = getId(product);

Describe alternatives you've considered

I could just write this function for use in my personal projects, but if this is a common problem/use-case I think including it in the library would be good so others could use it too

Additional context

No response

@pakrym-stripe
Copy link
Contributor

Hi @nathanhleung, thank you for your suggestion. I'll make it as future to gauge the interest in a helper like this.

@Sadaf-A
Copy link

Sadaf-A commented Aug 23, 2023

@pakrym-stripe Greetings, I would like to pick this up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants