-
-
Notifications
You must be signed in to change notification settings - Fork 504
/
conditional-pick-deep.ts
46 lines (38 loc) · 1.48 KB
/
conditional-pick-deep.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import {expectTypeOf} from 'expect-type';
import type {ConditionalPickDeep} from '../index';
type Example = {
a: string;
b: string | boolean;
c: {
d: string;
e: {
f?: string;
g?: boolean;
h: string | boolean;
i: boolean | bigint;
};
j: boolean;
};
};
declare const stringPick: ConditionalPickDeep<Example, string>;
expectTypeOf(stringPick).toEqualTypeOf<{a: string; c: {d: string}}>();
declare const stringPickOptional: ConditionalPickDeep<Example, string | undefined>;
expectTypeOf(stringPickOptional).toEqualTypeOf<{a: string; c: {d: string; e: {f?: string}}}>();
declare const stringPickOptionalOnly: ConditionalPickDeep<Example, string | undefined, {condition: 'equality'}>;
expectTypeOf(stringPickOptionalOnly).toEqualTypeOf<{c: {e: {f?: string}}}>();
declare const booleanPick: ConditionalPickDeep<Example, boolean | undefined>;
expectTypeOf(booleanPick).toEqualTypeOf<{c: {e: {g?: boolean}; j: boolean}}>();
declare const numberPick: ConditionalPickDeep<Example, number>;
expectTypeOf(numberPick).toEqualTypeOf<{}>();
declare const stringOrBooleanPick: ConditionalPickDeep<Example, string | boolean>;
expectTypeOf(stringOrBooleanPick).toEqualTypeOf<{
a: string;
b: string | boolean;
c: {
d: string;
e: {h: string | boolean};
j: boolean;
};
}>();
declare const stringOrBooleanPickOnly: ConditionalPickDeep<Example, string | boolean, {condition: 'equality'}>;
expectTypeOf(stringOrBooleanPickOnly).toEqualTypeOf<{b: string | boolean; c: {e: {h: string | boolean}}}>();