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

Add Stripe.Emptyable type definition #1052

Merged
merged 2 commits into from
Oct 26, 2020

Conversation

richardm-stripe
Copy link
Contributor

@richardm-stripe richardm-stripe commented Oct 26, 2020

r? @suz-stripe
cc @stripe/api-libraries

Defines Stripe.Emptyable<T> = null | '' | T type. Many params in the Stripe API has a "pass empty string to unset" idiom, and stripe-node converts nulls to empty strings over the wire. Presently, the type bindings encode all of these as T | null, but this is a bit confusing because some of the docstrings recommend empty strings.

I think adding an "Emptyable" wrapper like this will make the meaning of these type definitions a little bit more clear, and it also gives us a single place where we can document this behavior.

In VSCode, the present mouseover looks like
image
and the new one will be this:
image

It seems like VSCode omits mention of | null altogether, so the new mouseover is the only one that actually communicates the emptyable nature of the field .

types/lib.d.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@remi-stripe remi-stripe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving because the code is correct. I don't know much about Typescript though and I'm not sure how this will be used and whether it should be named Empty instead of Emptyable but deferring to you here. Don't hesitate to ask a review from someone familiar with TS instead

Copy link

@suz-stripe suz-stripe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this looks ok and don't have any strong feelings about the term Emptyable. After rolling alternatives around in my head, this seems like the most descriptive and specific way of putting it.

@richardm-stripe richardm-stripe merged commit f8b3194 into master Oct 26, 2020
@richardm-stripe richardm-stripe deleted the richardm-explicit-emptyable branch October 26, 2020 16:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants