sindresorhus/type-fest

`EmptyArray` type

silverwind opened this issue · 2 comments

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

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

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.