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

feat(join): support more cases #594

Merged
merged 7 commits into from Apr 25, 2023
Merged

Conversation

eranhirsch
Copy link
Contributor

@eranhirsch eranhirsch commented Apr 13, 2023

I recently worked on typing the builtin Array.prototype.join method in order to handle cases of non-empty arrays (aka tuple with rest param [...T[], T]).

Type-fest is my primary goto for complex typing but I saw that the type defined here is missing support for this.

Here I try to provide the fullest signature for join that I could muster.

The join type now supports:

  1. undefined and null values
  2. bigints (as numbers) and booleans (by coalescing to the actual string value)
  3. tuples with rest "heads"
  4. A final optional value in the tuple (but not more than one! I couldn't get it to work)

source/join.d.ts Outdated
const path: Join<[true, false, true], '.'> = [true, false, true].join('.');

// Contains nullish items; result is: 'foo..baz..xyz'
const path: Join<['foo', undefined, 'baz', null, 'xyz'], '.'> = ['foo', undefined, null, 'baz', undefined, 'xyz'].join('.');
Copy link
Owner

Choose a reason for hiding this comment

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

Typo ^

Copy link
Owner

Choose a reason for hiding this comment

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

null is in different position.

@sindresorhus sindresorhus merged commit bb81314 into sindresorhus:main Apr 25, 2023
7 checks passed
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.

None yet

2 participants