Add EmptyArray type - #1513
Add EmptyArray type#1513vjymisal0 wants to merge 3 commits into
EmptyArray type#1513Conversation
|
I think I am less convinced about adding If we do keep type Result = IsEmptyArray<never>;
//=> never
type Branch = IsEmptyArray<never> extends true ? 'empty' : 'not empty';
//=> 'empty'The type says it returns a boolean, and the existing The tests are also missing the boundary cases mentioned in the PR description. At minimum, I would cover The current index assignment test does not actually verify readonly behavior because it also fails for mutable The documentation should also link to #929 and briefly explain that the implementation is a readonly empty tuple, as requested by the contribution guide. If the predicate stays distributive, its union behavior should be documented too, since “strictly equal” suggests that |
ac4fcdb to
91e612d
Compare
|
Thanks for the careful review. I kept the PR focused on |
Adds
EmptyArray(and a companionIsEmptyArray), mirroring the existingEmptyObject/IsEmptyObjectpair.Closes #929
unknown[]/any[]can't represent a strictly empty array — this is the array equivalent of the{}-vs-EmptyObjectproblem already solved for objects. Modeled asreadonly [], matching what[] as constalready produces (as noted in the issue).source/empty-array.d.ts—EmptyArray+IsEmptyArray, following theempty-object.d.tsdoc/test conventionstest-d/empty-array.ts— assignability, mutation rejection, and union-narrowing tests, plusany/never/unknown-style edge casesindex.d.tsandreadme.mdnpm test(tsc, tsd, xo) passes locally.