-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Lexus Drumgold <[email protected]>
- Loading branch information
1 parent
bb2bc85
commit 4c251c1
Showing
3 changed files
with
33 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/** | ||
* @file Type Tests - TupleToUnion | ||
* @module tutils/types/tests/unit-d/TupleToUnion | ||
*/ | ||
|
||
import type TestSubject from '../tuple-to-union' | ||
|
||
describe('unit-d:types/TupleToUnion', () => { | ||
it('should equal tuple elements union if T is a tuple', () => { | ||
expectTypeOf<TestSubject<[0, 1, 2]>>().toEqualTypeOf<0 | 1 | 2>() | ||
}) | ||
|
||
it('should equal never if T is not a tuple', () => { | ||
expectTypeOf<TestSubject<number>>().toBeNever() | ||
}) | ||
}) |
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,16 @@ | ||
/** | ||
* @file Type Definitions - TupleToUnion | ||
* @module tutils/types/TupleToUnion | ||
*/ | ||
|
||
/** | ||
* Converts a [tuple][1] to a [union][2]. | ||
* | ||
* [1]: https://www.codecademy.com/resources/docs/typescript/tuples | ||
* [2]: https://www.typescriptlang.org/docs/handbook/unions-and-intersections#union-types | ||
* | ||
* @template T - Type to evaluate | ||
*/ | ||
type TupleToUnion<T> = T extends readonly unknown[] ? T[number] : never | ||
|
||
export type { TupleToUnion as default } |