-
Notifications
You must be signed in to change notification settings - Fork 0
/
_internal.ts
64 lines (49 loc) · 1.75 KB
/
_internal.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
export {
filterEntries,
filterKeys,
isKeyOf,
isObject,
mapEntries,
mapKeys,
objectPick,
} from "./deps.ts";
export type Primitive = string | number | bigint | boolean | symbol;
export type LiteralUnion<
Literal extends BaseType,
BaseType extends Primitive,
> = Literal | (BaseType & Record<never, never>);
export type JSONReplacerFn = (this: any, key: string, value: any) => any;
export type JSONReplacerArray = (string | number)[];
export type JSONReviverFn = (this: any, key: string, value: any) => any;
export type JsonValue =
| { [key: string]: JsonValue | undefined }
| JsonValue[]
| string
| number
| boolean
| null;
export type { JsonValue as JSONValue };
export type Entry<K extends PropertyKey = string, V extends unknown = string> =
readonly [K, V];
export type Merge<T, Deep = false> = T extends
infer U extends Record<string, unknown>
? { [K in keyof U]: Deep extends true ? Merge<U[K], Deep> : U[K] }
: T;
export type MergeTuples<A extends Tuple, B extends Tuple = []> = [...A, ...B];
export type Tuple<T = unknown, ReadOnly = true> = ReadOnly extends true
? readonly T[]
: T[];
export type Writable<T, Deep = false> = T extends Record<string, unknown> ? {
-readonly [K in keyof T]?: Deep extends true ? Writable<T[K], true> : T[K];
}
: T;
export type Readonly<T, Deep = false> = T extends Record<string, unknown> ? {
readonly [K in keyof T]?: Deep extends true ? Readonly<T[K], Deep> : T[K];
}
: T;
export type Optional<T, Deep = false> = T extends Record<string, unknown>
? { [K in keyof T]?: Deep extends true ? Optional<T[K], Deep> : T[K] }
: T;
export type Required<T, Deep = false> = T extends Record<string, unknown>
? { [K in keyof T]-?: Deep extends true ? Required<T[K], Deep> : T[K] }
: T;