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

EmptyArray type #929

Open
silverwind opened this issue Aug 6, 2024 · 2 comments · May be fixed by #931
Open

EmptyArray type #929

silverwind opened this issue Aug 6, 2024 · 2 comments · May be fixed by #931
Labels
help wanted Extra attention is needed type addition

Comments

@silverwind
Copy link

silverwind commented Aug 6, 2024

There is EmptyObject, and I think a EmptyArray type for a strictly empty array would be useful.

One use case of empty array with React to avoid re-renders because of unstable default prop:

const defaultArr = [];
const Component = ({arr = defaultArr}) => arr.join(",");

Upvote & Fund

  • We're using Polar.sh so you can upvote and help fund this issue.
  • The funding will be given to active contributors.
  • Thank you in advance for helping prioritize & fund our backlog.
Fund with Polar
@sindresorhus
Copy link
Owner

You could do it with [] as const, but it could be nice to have a type for this too, for discoverability.

We already have https://github.com/sindresorhus/type-fest/blob/main/source/non-empty-tuple.d.ts

@sindresorhus sindresorhus added help wanted Extra attention is needed type addition labels Aug 6, 2024
@silverwind
Copy link
Author

silverwind commented Aug 6, 2024

Yeah I guess this type would mostly be for completeness sake. I guess EmptyObject has a reason for existence because of the mentioned problems surrounding the {} type that [] hopefully doesn't have.

silverwind added a commit to silverwind/type-fest that referenced this issue Aug 8, 2024
silverwind added a commit to silverwind/type-fest that referenced this issue Aug 8, 2024
silverwind added a commit to silverwind/type-fest that referenced this issue Aug 8, 2024
silverwind added a commit to silverwind/type-fest that referenced this issue Aug 8, 2024
silverwind added a commit to silverwind/type-fest that referenced this issue Aug 8, 2024
@silverwind silverwind linked a pull request Aug 8, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed type addition
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants