-
-
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
eade439
commit 435a9c4
Showing
3 changed files
with
71 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,47 @@ | ||
/** | ||
* @file Type Tests - Shake | ||
* @module tutils/types/tests/unit-d/Shake | ||
*/ | ||
|
||
import type Vehicle from '#fixtures/types/vehicle' | ||
import type Fn from '../fn' | ||
import type NumberString from '../number-string' | ||
import type Optional from '../optional' | ||
import type Partial from '../partial' | ||
import type TestSubject from '../shake' | ||
|
||
describe('unit-d:types/Shake', () => { | ||
it('should equal {} if F is any', () => { | ||
expectTypeOf<TestSubject<Vehicle, any>>().toEqualTypeOf<{}>() | ||
}) | ||
|
||
it('should equal T if F is never', () => { | ||
expectTypeOf<TestSubject<Vehicle, never>>().toEqualTypeOf<Vehicle>() | ||
}) | ||
|
||
describe('T extends ObjectCurly', () => { | ||
it('should exclude F from T', () => { | ||
// Arrange | ||
type T = { vin: string; year: NumberString } | ||
type F = string | ||
|
||
// Expect | ||
expectTypeOf<TestSubject<T, F>>().toEqualTypeOf<{ | ||
year: Exclude<NumberString, F> | ||
}>() | ||
}) | ||
}) | ||
|
||
describe('unions', () => { | ||
it('should distribute over unions', () => { | ||
// Arrange | ||
type T = Partial<Vehicle> | Vehicle | ||
type F = Optional<Fn | string> | ||
|
||
// Expect | ||
expectTypeOf<TestSubject<T, F>>().toEqualTypeOf< | ||
{ year: Vehicle['year'] } | { year?: Vehicle['year'] } | ||
>() | ||
}) | ||
}) | ||
}) |
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,23 @@ | ||
/** | ||
* @file Type Definitions - Shake | ||
* @module tutils/types/Shake | ||
*/ | ||
|
||
import type ObjectCurly from './object-curly' | ||
|
||
/** | ||
* Filter `T` by removing keys where the key-value non-distributively extends | ||
* filter condition `F`, and exclude `F` from any remaining key values. | ||
* | ||
* **Note**: Does **not** make optional keys required. | ||
* | ||
* @todo examples | ||
* | ||
* @template T - Type to evaluate | ||
* @template F - Key value filter | ||
*/ | ||
type Shake<T extends ObjectCurly, F = undefined> = T extends unknown | ||
? { [K in keyof T as T[K] extends F ? never : K]: Exclude<T[K], F> } | ||
: never | ||
|
||
export type { Shake as default } |