-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.test-d.ts
103 lines (95 loc) · 2.14 KB
/
index.test-d.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import {
Input,
Int,
Float,
int,
float,
word,
tuple,
shape,
someOf,
times,
join,
oneOf,
oneOfWeighted
} from '.'
export const expectType = <T>(value: T) => {};
// ## function items
expectType<[number, string]>(tuple(null, [int, word]))
expectType<string>(join(null, ' ', [int, word]))
expectType<number | string>(oneOf(null, [int, word]))
expectType<number | string>(
oneOfWeighted(null, [
[0.6, int],
[0.4, word]
])
)
expectType<(number | string)[]>(someOf(null, [2, 3], [int, word]))
expectType<number[]>(times(null, [2, 3], int))
expectType<{
a: number
b: string
}>(
shape(null, {
a: int,
b: word
})
)
// ## constant items
expectType<[number, string]>(tuple(null, [2, '!']))
expectType<string>(join(null, ' ', [2, '!']))
expectType<number | string>(oneOf(null, [2, '!']))
expectType<number | string>(
oneOfWeighted(null, [
[0.6, 2],
[0.4, '!']
])
)
expectType<(number | string)[]>(someOf(null, [3, 3], [2, '!']))
expectType<number[]>(times(null, [2, 3], 23))
expectType<{
a: number
b: string
}>(
shape(null, {
a: 2,
b: '!'
})
)
// ## currying
expectType<(input: Input) => [number]>(tuple([int]))
expectType<(input: Input) => string>(join(' ', [int, word]))
expectType<(input: Input) => number>(oneOf([2, 3]))
expectType<(input: Input) => number>(
oneOfWeighted([
[0.6, 2],
[0.6, 3]
])
)
expectType<(input: Input) => string[]>(someOf([3, 3], ['a', 'b']))
expectType<(input: Input) => string[]>(times([2, 3], word))
expectType<
(
input: Input
) => {
a: number
b: string
}
>(
shape({
a: int,
b: word
})
)
// ## join: joiner types
declare function numJoiner(v: (number | string)[]): number
expectType<string>(join(null, ' ', [2, '!']))
expectType<number>(join(null, numJoiner, [2, '!']))
// ## options chaining
expectType<Int>(int.options({ min: 2 }).options({ max: 3 }))
expectType<Float>(float.options({ min: 2 }).options({ max: 3 }))
// ## range values
expectType<string[]>(times(null, 2, word))
expectType<string[]>(times(null, [2, 3], word))
expectType<string[]>(someOf(null, 2, ['a', 'b', 'c']))
expectType<string[]>(someOf(null, [2, 3], ['a', 'b', 'c']))