-
-
Notifications
You must be signed in to change notification settings - Fork 502
/
partial-on-undefined-deep.ts
78 lines (75 loc) · 2.63 KB
/
partial-on-undefined-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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import {expectAssignable} from 'tsd';
import type {PartialOnUndefinedDeep} from '../index';
type TestingType = {
function: (() => void) | undefined;
object: {objectKey: 1} | undefined;
objectDeep: {
subObject: string | undefined;
};
string: string | undefined;
union: 'test1' | 'test2' | undefined;
number: number | undefined;
boolean: boolean | undefined;
date: Date | undefined;
regexp: RegExp | undefined;
symbol: symbol | undefined;
null: null | undefined;
record: Record<string, any> | undefined;
map: Map<string, string> | undefined;
set: Set<string> | undefined;
array1: any[] | undefined;
array2: Array<{propertyA: string; propertyB: number | undefined}> | undefined;
readonly1: readonly any[] | undefined;
readonly2: ReadonlyArray<{propertyA: string; propertyB: number | undefined}> | undefined;
tuple: ['test1', {propertyA: string; propertyB: number | undefined}] | undefined;
};
// Default behavior, without recursion into arrays/tuples
declare const foo: PartialOnUndefinedDeep<TestingType>;
expectAssignable<{
function?: TestingType['function'];
object?: TestingType['object'];
objectDeep: {
subObject?: TestingType['objectDeep']['subObject'];
};
string?: TestingType['string'];
union?: TestingType['union'];
number?: TestingType['number'];
boolean?: TestingType['boolean'];
date?: TestingType['date'];
regexp?: TestingType['regexp'];
symbol?: TestingType['symbol'];
null?: TestingType['null'];
record?: TestingType['record'];
map?: TestingType['map'];
set?: TestingType['set'];
array1?: TestingType['array1'];
array2?: TestingType['array2'];
readonly1?: TestingType['readonly1'];
readonly2?: TestingType['readonly2'];
tuple?: TestingType['tuple'];
}>(foo);
// With recursion into arrays/tuples activated
declare const bar: PartialOnUndefinedDeep<TestingType, {recurseIntoArrays: true}>;
expectAssignable<{
function?: TestingType['function'];
object?: TestingType['object'];
objectDeep: {
subObject?: TestingType['objectDeep']['subObject'];
};
string?: TestingType['string'];
union?: TestingType['union'];
number?: TestingType['number'];
boolean?: TestingType['boolean'];
date?: TestingType['date'];
regexp?: TestingType['regexp'];
symbol?: TestingType['symbol'];
null?: TestingType['null'];
record?: TestingType['record'];
map?: TestingType['map'];
set?: TestingType['set'];
array1?: TestingType['array1'];
array2?: Array<{propertyA: string; propertyB?: number | undefined}> | undefined;
readonly1?: TestingType['readonly1'];
readonly2?: ReadonlyArray<{propertyA: string; propertyB?: number | undefined}> | undefined;
tuple?: ['test1', {propertyA: string; propertyB?: number | undefined}] | undefined;
}>(bar);