-
-
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
1fa5c84
commit 95d4115
Showing
3 changed files
with
73 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,48 @@ | ||
/** | ||
* @file Type Tests - ArrayFallback | ||
* @module tutils/types/tests/unit-d/ArrayFallback | ||
*/ | ||
|
||
import type Vehicle from '#fixtures/types/vehicle' | ||
import type EmptyArray from '../empty-array' | ||
import type TestSubject from '../fallback-array' | ||
import type Nilable from '../nilable' | ||
import type Partial from '../partial' | ||
|
||
describe('unit-d:types/ArrayFallback', () => { | ||
it('should equal F if T extends NIL', () => { | ||
// Arrange | ||
type F = [Partial<Vehicle>] | ||
|
||
// Expect | ||
expectTypeOf<TestSubject<null, F>>().toEqualTypeOf<F>() | ||
expectTypeOf<TestSubject<undefined, F>>().toEqualTypeOf<F>() | ||
}) | ||
|
||
it('should equal T if IsAny<T> extends true', () => { | ||
// Arrange | ||
type T = any | ||
|
||
// Expect | ||
expectTypeOf<TestSubject<T>>().toEqualTypeOf<T>() | ||
}) | ||
|
||
it('should equal T if T extends {}', () => { | ||
// Arrange | ||
type T = Vehicle | ||
|
||
// Expect | ||
expectTypeOf<TestSubject<T>>().toEqualTypeOf<T>() | ||
}) | ||
|
||
describe('unions', () => { | ||
it('should distribute over unions', () => { | ||
// Arrange | ||
type T = Nilable<readonly [Vehicle, Vehicle]> | ||
type Expect = EmptyArray | NonNullable<T> | ||
|
||
// Expect | ||
expectTypeOf<TestSubject<T>>().toEqualTypeOf<Expect>() | ||
}) | ||
}) | ||
}) |
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,24 @@ | ||
/** | ||
* @file Type Definitions - ArrayFallback | ||
* @module tutils/types/ArrayFallback | ||
*/ | ||
|
||
import type EmptyArray from './empty-array' | ||
import type Fallback from './fallback' | ||
import type NIL from './nil' | ||
|
||
/** | ||
* Fallback to an array type if `T` extends {@linkcode NIL}. | ||
* | ||
* @todo examples | ||
* | ||
* @template T - Type to evaluate | ||
* @template [F=EmptyArray] - Fallback array type | ||
*/ | ||
type ArrayFallback<T, F extends readonly unknown[] = EmptyArray> = Fallback< | ||
T, | ||
F, | ||
NIL | ||
> | ||
|
||
export type { ArrayFallback as default } |
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