-
-
Notifications
You must be signed in to change notification settings - Fork 544
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
128b21e
commit bb57638
Showing
6 changed files
with
34 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/** | ||
Matches any non-empty tuple. | ||
@example | ||
``` | ||
import type {NonEmptyTuple} from 'type-fest'; | ||
const sum = (...numbers: NonEmptyTuple<number>) => numbers.reduce((total, value) => total + value, 0); | ||
sum(1, 2, 3); | ||
//=> 6 | ||
sum(); | ||
//=> Error: Expected at least 1 arguments, but got 0. | ||
``` | ||
@see {@link RequireAtLeastOne} for objects | ||
@category Array | ||
*/ | ||
export type NonEmptyTuple<T = unknown> = readonly [T, ...T[]]; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import {expectType} from 'tsd'; | ||
import type {NonEmptyTuple} from '../index'; | ||
|
||
declare const sum: (...numbers: NonEmptyTuple<number>) => number; | ||
|
||
expectType<number>(sum(1, 2, 3)); | ||
expectType<number>(sum(1)); | ||
|
||
// @ts-expect-error | ||
sum(); |