Add EmptyArray and IsEmptyArray types#1355
Open
derodero24 wants to merge 1 commit into
Open
Conversation
sindresorhus
reviewed
Feb 9, 2026
|
|
||
| // IsEmptyArray — Edge cases | ||
| expectType<IsEmptyArray<any>>(false); | ||
| expectType<IsEmptyArray<never>>(false); |
Owner
There was a problem hiding this comment.
Some more tests:
Suggested change
| expectType<IsEmptyArray<never>>(false); | |
| expectType<IsEmptyArray<never>>(false); | |
| // IsEmptyArray — Union behavior | |
| expectType<IsEmptyArray<[] | [1]>>({} as boolean); | |
| expectType<IsEmptyArray<readonly [] | readonly [1]>>({} as boolean); | |
| // IsEmptyArray — More non-empty/array boundaries | |
| expectType<IsEmptyArray<[never]>>(false); | |
| expectType<IsEmptyArray<unknown[]>>(false); | |
| expectType<IsEmptyArray<any[]>>(false); |
Owner
There was a problem hiding this comment.
Maybe also:
// @ts-expect-error
emptyArray.length = 1;
sindresorhus
reviewed
Feb 9, 2026
|
|
||
| @category Array | ||
| */ | ||
| export type EmptyArray = never[]; |
Owner
There was a problem hiding this comment.
Why not
Suggested change
| export type EmptyArray = never[]; | |
| export type EmptyArray = []; |
?
Contributor
Author
There was a problem hiding this comment.
All addressed — simplified to [], added union/boundary tests, and the length immutability test.
4224f8a to
e94dd86
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #929
Adds
EmptyArray(never[]) for representing a strictly empty array, analogous toEmptyObject. Also addsIsEmptyArray<T>as a type guard.IsEmptyArrayhandles:[],never[],readonly [],readonly never[]→truestring[],any,never→falseThis picks up where #931 left off, with the readonly array tests that were requested in review.