-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.ts
More file actions
54 lines (43 loc) · 1.17 KB
/
utils.ts
File metadata and controls
54 lines (43 loc) · 1.17 KB
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
export type Includes<T, Item> =
T extends [infer First, ...infer Rest] ?
First extends Item ?
true
: Includes<Rest, Item>
: false
export type ConcatIfNotFound<T extends unknown[], Item> = Includes<
T,
Item
> extends true ?
T
: [...T, Item]
export type Prettify<T> = {
[K in keyof T]: T[K] extends object ? Prettify<T[K]> : T[K]
} & unknown
type pretty = Prettify<{ k1: 'v1' } & { k2: 'v2' }>
export type And<A, B> =
A extends true ?
B extends true ?
true
: false
: false
type testAnd = And<true, false>
type testAnd1 = And<true, true>
export type Or<A, B> =
A extends true ? true
: B extends true ? true
: false
type testOr = Or<true, false>
type testOr1 = Or<false, false>
// want empty to be last case
export type NotEmpty<S extends string> = S extends '' ? false : true
// T extends never won't work
export type IsNever<T> = [T] extends [never] ? true : false
// (1 | 2)[] extends (1[] | 2[])
export type IsUnion<T> = T[] extends (T extends T ? T[] : never) ? false : true
export type DeepMutable<T> = {
-readonly [K in keyof T]: T[K] extends (
Record<string, unknown> | readonly unknown[]
) ?
DeepMutable<T[K]>
: T[K]
}