stripe-node icon indicating copy to clipboard operation
stripe-node copied to clipboard

Invoice.id is shouldn't be optional

Open deldrid1 opened this issue 3 years ago • 3 comments

Describe the bug

According to https://stripe.com/docs/api/invoices/line_item#invoice_line_item_object-id, invoice.id should be required.

As I am upgrading to v10.0.0, it looks like it was made optional

https://github.com/stripe/stripe-node/blob/0cd1aa77f2a14f4446bc6190c908e78244f19c3b/types/2022-08-01/Invoices.d.ts#L12

To Reproduce

Perform any operation on an invoice and get an incorrectly typed object as the response.

Expected behavior

This should be a required property so I don't have to litter my code with unnecessary run-time undefined checks.

Code snippets

No response

OS

macOS

Node version

All Node Version

Library version

stripe-node v10.0.0

API version

2022-08-01

Additional context

No response

deldrid1 avatar Aug 03 '22 14:08 deldrid1

Any update on this? Would like to avoid all the extra null checks 🙂

snlamm avatar Sep 08 '22 05:09 snlamm

We're working on the issue with the product team. Apologies for the delay. The resource represents both Invoice and UpcomingInvoice, where the ID is optional. That's why it was made optional and the fix is not as easy as reverting the change.

kamil-stripe avatar Sep 08 '22 16:09 kamil-stripe

Thanks for the update!

snlamm avatar Sep 08 '22 16:09 snlamm

Any update on this issue ? The type is still optional for v11.1.0 : https://github.com/stripe/stripe-node/blob/v11.1.0/types/2022-11-15/Invoices.d.ts#L43

michelbl avatar Nov 28 '22 16:11 michelbl

Can someone from stripe explain why it was done like this ? and not with a upcomingInvoice Type ? as done in the PR ?

julestruong avatar Dec 01 '22 16:12 julestruong

Hello @julestruong.

Our default strategy is to establish a single type for each "resource" that is broad enough to capture the return values of all the methods on that resource, so because retrieveUpcoming is on the Invoice resource, we expanded the Invoice type to be able to describe its return value and made id optional.

We have a pretty strong bias against making exceptions to our default patterns. Even when an exception makes an interface locally better, a library that's full of special cases is globally worse. Given all the feedback here though, it's pretty clear that #1629 is the way to go.

richardm-stripe avatar Dec 01 '22 18:12 richardm-stripe

That was really nice of you to take the time to explain your strategy. Thank you. I'll patch the changes in the PR then , waiting for its merge.

julestruong avatar Dec 01 '22 18:12 julestruong