@lee-zg/melange 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +256 -0
- package/dist/chunk-2PXWQDZC.js +659 -0
- package/dist/chunk-2PXWQDZC.js.map +1 -0
- package/dist/chunk-352XNR3C.js +716 -0
- package/dist/chunk-352XNR3C.js.map +1 -0
- package/dist/chunk-7QVYU63E.js +6 -0
- package/dist/chunk-7QVYU63E.js.map +1 -0
- package/dist/chunk-ALBD5XC5.js +285 -0
- package/dist/chunk-ALBD5XC5.js.map +1 -0
- package/dist/chunk-O7K662J5.cjs +842 -0
- package/dist/chunk-O7K662J5.cjs.map +1 -0
- package/dist/chunk-PK6SKIKE.cjs +8 -0
- package/dist/chunk-PK6SKIKE.cjs.map +1 -0
- package/dist/chunk-Q73NOVWX.cjs +789 -0
- package/dist/chunk-Q73NOVWX.cjs.map +1 -0
- package/dist/chunk-Q7XG6YN6.cjs +682 -0
- package/dist/chunk-Q7XG6YN6.cjs.map +1 -0
- package/dist/chunk-YGMBCZJQ.js +833 -0
- package/dist/chunk-YGMBCZJQ.js.map +1 -0
- package/dist/chunk-ZT6HVG4G.cjs +330 -0
- package/dist/chunk-ZT6HVG4G.cjs.map +1 -0
- package/dist/core/index.cjs +97 -0
- package/dist/core/index.cjs.map +1 -0
- package/dist/core/index.d.cts +718 -0
- package/dist/core/index.d.ts +718 -0
- package/dist/core/index.js +4 -0
- package/dist/core/index.js.map +1 -0
- package/dist/fp/index.cjs +185 -0
- package/dist/fp/index.cjs.map +1 -0
- package/dist/fp/index.d.cts +913 -0
- package/dist/fp/index.d.ts +913 -0
- package/dist/fp/index.js +4 -0
- package/dist/fp/index.js.map +1 -0
- package/dist/index.cjs +608 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +39 -0
- package/dist/index.d.ts +39 -0
- package/dist/index.js +33 -0
- package/dist/index.js.map +1 -0
- package/dist/plugins/index.cjs +41 -0
- package/dist/plugins/index.cjs.map +1 -0
- package/dist/plugins/index.d.cts +643 -0
- package/dist/plugins/index.d.ts +643 -0
- package/dist/plugins/index.js +4 -0
- package/dist/plugins/index.js.map +1 -0
- package/dist/types-BtOUCLB-.d.cts +293 -0
- package/dist/types-BtOUCLB-.d.ts +293 -0
- package/dist/utils/index.cjs +297 -0
- package/dist/utils/index.cjs.map +1 -0
- package/dist/utils/index.d.cts +1179 -0
- package/dist/utils/index.d.ts +1179 -0
- package/dist/utils/index.js +4 -0
- package/dist/utils/index.js.map +1 -0
- package/package.json +132 -0
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Melange 库的核心类型定义
|
|
3
|
+
* @module melange/types
|
|
4
|
+
* @description 全面的 TypeScript 类型定义,支持函数式编程、
|
|
5
|
+
* 面向对象模式和 Melange 库的工具类型。
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* 表示可为空的类型,可以是类型 T 或 null/undefined
|
|
9
|
+
* @template T - 基础类型
|
|
10
|
+
*/
|
|
11
|
+
type Nullable<T> = T | null | undefined;
|
|
12
|
+
/**
|
|
13
|
+
* 表示可选类型,可以是类型 T 或 undefined
|
|
14
|
+
* @template T - 基础类型
|
|
15
|
+
*/
|
|
16
|
+
type Optional<T> = T | undefined;
|
|
17
|
+
/**
|
|
18
|
+
* 表示原始 JavaScript 类型
|
|
19
|
+
*/
|
|
20
|
+
type Primitive = string | number | boolean | symbol | bigint | null | undefined;
|
|
21
|
+
/**
|
|
22
|
+
* 表示任何函数类型
|
|
23
|
+
*/
|
|
24
|
+
type AnyFunction = (...args: unknown[]) => unknown;
|
|
25
|
+
/**
|
|
26
|
+
* 表示构造函数类型
|
|
27
|
+
* @template T - 实例类型
|
|
28
|
+
*/
|
|
29
|
+
type Constructor<T = object> = new (...args: unknown[]) => T;
|
|
30
|
+
/**
|
|
31
|
+
* 表示不接受参数并返回值的函数
|
|
32
|
+
* @template T - 返回类型
|
|
33
|
+
*/
|
|
34
|
+
type Thunk<T> = () => T;
|
|
35
|
+
/**
|
|
36
|
+
* 表示返回布尔值的谓词函数
|
|
37
|
+
* @template T - 输入类型
|
|
38
|
+
*/
|
|
39
|
+
type Predicate<T> = (value: T) => boolean;
|
|
40
|
+
/**
|
|
41
|
+
* 表示从类型 A 到类型 B 的映射函数
|
|
42
|
+
* @template A - 输入类型
|
|
43
|
+
* @template B - 输出类型
|
|
44
|
+
*/
|
|
45
|
+
type Mapper<A, B> = (value: A) => B;
|
|
46
|
+
/**
|
|
47
|
+
* 表示用于折叠/归约操作的归约函数
|
|
48
|
+
* @template T - 累加器类型
|
|
49
|
+
* @template U - 当前值类型
|
|
50
|
+
*/
|
|
51
|
+
type Reducer<T, U> = (accumulator: T, current: U) => T;
|
|
52
|
+
/**
|
|
53
|
+
* 表示用于排序的比较函数
|
|
54
|
+
* @template T - 被比较的类型
|
|
55
|
+
*/
|
|
56
|
+
type Comparator<T> = (a: T, b: T) => number;
|
|
57
|
+
/**
|
|
58
|
+
* 表示一元函数(单参数)
|
|
59
|
+
* @template A - 输入类型
|
|
60
|
+
* @template B - 输出类型
|
|
61
|
+
*/
|
|
62
|
+
type UnaryFunction<A, B> = (arg: A) => B;
|
|
63
|
+
/**
|
|
64
|
+
* 表示二元函数(两个参数)
|
|
65
|
+
* @template A - 第一个参数类型
|
|
66
|
+
* @template B - 第二个参数类型
|
|
67
|
+
* @template C - 返回类型
|
|
68
|
+
*/
|
|
69
|
+
type BinaryFunction<A, B, C> = (a: A, b: B) => C;
|
|
70
|
+
/**
|
|
71
|
+
* 表示柯里化的二元函数
|
|
72
|
+
* @template A - 第一个参数类型
|
|
73
|
+
* @template B - 第二个参数类型
|
|
74
|
+
* @template C - 返回类型
|
|
75
|
+
*/
|
|
76
|
+
type CurriedBinaryFunction<A, B, C> = (a: A) => (b: B) => C;
|
|
77
|
+
/**
|
|
78
|
+
* 表示成功的结果
|
|
79
|
+
* @template T - 成功值类型
|
|
80
|
+
*/
|
|
81
|
+
interface Ok<T> {
|
|
82
|
+
readonly _tag: 'Ok';
|
|
83
|
+
readonly value: T;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* 表示失败的结果
|
|
87
|
+
* @template E - 错误类型
|
|
88
|
+
*/
|
|
89
|
+
interface Err<E> {
|
|
90
|
+
readonly _tag: 'Err';
|
|
91
|
+
readonly error: E;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* 表示用于错误处理的 Result 类型
|
|
95
|
+
* @template T - 成功值类型
|
|
96
|
+
* @template E - 错误类型
|
|
97
|
+
*/
|
|
98
|
+
type Result<T, E> = Ok<T> | Err<E>;
|
|
99
|
+
/**
|
|
100
|
+
* 表示存在的值
|
|
101
|
+
* @template T - 值类型
|
|
102
|
+
*/
|
|
103
|
+
interface Some<T> {
|
|
104
|
+
readonly _tag: 'Some';
|
|
105
|
+
readonly value: T;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* 表示缺失的值
|
|
109
|
+
*/
|
|
110
|
+
interface None {
|
|
111
|
+
readonly _tag: 'None';
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* 表示用于可空值处理的 Option 类型
|
|
115
|
+
* @template T - 值类型
|
|
116
|
+
*/
|
|
117
|
+
type Option<T> = Some<T> | None;
|
|
118
|
+
/**
|
|
119
|
+
* 表示异步函数
|
|
120
|
+
* @template T - 返回类型
|
|
121
|
+
*/
|
|
122
|
+
type AsyncFunction<T> = (...args: unknown[]) => Promise<T>;
|
|
123
|
+
/**
|
|
124
|
+
* 表示异步 thunk
|
|
125
|
+
* @template T - 返回类型
|
|
126
|
+
*/
|
|
127
|
+
type AsyncThunk<T> = () => Promise<T>;
|
|
128
|
+
/**
|
|
129
|
+
* 表示可能已解析或未解析的延迟值
|
|
130
|
+
* @template T - 值类型
|
|
131
|
+
*/
|
|
132
|
+
interface Deferred<T> {
|
|
133
|
+
promise: Promise<T>;
|
|
134
|
+
resolve: (value: T) => void;
|
|
135
|
+
reject: (reason?: unknown) => void;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* 表示具有字符串键的记录
|
|
139
|
+
* @template T - 值类型
|
|
140
|
+
*/
|
|
141
|
+
type Dictionary<T> = Record<string, T>;
|
|
142
|
+
/**
|
|
143
|
+
* 表示深层部分类型
|
|
144
|
+
* @template T - 基础类型
|
|
145
|
+
*/
|
|
146
|
+
type DeepPartial<T> = T extends object ? {
|
|
147
|
+
[P in keyof T]?: DeepPartial<T[P]>;
|
|
148
|
+
} : T;
|
|
149
|
+
/**
|
|
150
|
+
* 表示深层只读类型
|
|
151
|
+
* @template T - 基础类型
|
|
152
|
+
*/
|
|
153
|
+
type DeepReadonly<T> = T extends object ? {
|
|
154
|
+
readonly [P in keyof T]: DeepReadonly<T[P]>;
|
|
155
|
+
} : T;
|
|
156
|
+
/**
|
|
157
|
+
* 使指定键变为必需
|
|
158
|
+
* @template T - 基础类型
|
|
159
|
+
* @template K - 要设为必需的键
|
|
160
|
+
*/
|
|
161
|
+
type RequiredKeys<T, K extends keyof T> = T & Required<Pick<T, K>>;
|
|
162
|
+
/**
|
|
163
|
+
* 使指定键变为可选
|
|
164
|
+
* @template T - 基础类型
|
|
165
|
+
* @template K - 要设为可选的键
|
|
166
|
+
*/
|
|
167
|
+
type OptionalKeys<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
168
|
+
/**
|
|
169
|
+
* 提取对象类型的键
|
|
170
|
+
* @template T - 对象类型
|
|
171
|
+
*/
|
|
172
|
+
type Keys<T> = keyof T;
|
|
173
|
+
/**
|
|
174
|
+
* 提取对象的值类型
|
|
175
|
+
* @template T - 对象类型
|
|
176
|
+
*/
|
|
177
|
+
type Values<T> = T[keyof T];
|
|
178
|
+
/**
|
|
179
|
+
* 表示一对值
|
|
180
|
+
* @template A - 第一个值类型
|
|
181
|
+
* @template B - 第二个值类型
|
|
182
|
+
*/
|
|
183
|
+
type Pair<A, B> = readonly [A, B];
|
|
184
|
+
/**
|
|
185
|
+
* 表示三元组值
|
|
186
|
+
* @template A - 第一个值类型
|
|
187
|
+
* @template B - 第二个值类型
|
|
188
|
+
* @template C - 第三个值类型
|
|
189
|
+
*/
|
|
190
|
+
type Triple<A, B, C> = readonly [A, B, C];
|
|
191
|
+
/**
|
|
192
|
+
* 提取元组的头部(第一个元素)
|
|
193
|
+
* @template T - 元组类型
|
|
194
|
+
*/
|
|
195
|
+
type Head<T extends readonly unknown[]> = T extends readonly [infer H, ...unknown[]] ? H : never;
|
|
196
|
+
/**
|
|
197
|
+
* 提取元组的尾部(除第一个元素外的所有元素)
|
|
198
|
+
* @template T - 元组类型
|
|
199
|
+
*/
|
|
200
|
+
type Tail<T extends readonly unknown[]> = T extends readonly [unknown, ...infer Rest] ? Rest : never;
|
|
201
|
+
/**
|
|
202
|
+
* 表示类装饰器
|
|
203
|
+
* @template T - 类类型
|
|
204
|
+
*/
|
|
205
|
+
type ClassDecorator<T extends Constructor> = (target: T) => T | void;
|
|
206
|
+
/**
|
|
207
|
+
* 表示方法装饰器
|
|
208
|
+
*/
|
|
209
|
+
type MethodDecorator = (target: object, propertyKey: string | symbol, descriptor: PropertyDescriptor) => PropertyDescriptor | void;
|
|
210
|
+
/**
|
|
211
|
+
* 表示属性装饰器
|
|
212
|
+
*/
|
|
213
|
+
type PropertyDecorator = (target: object, propertyKey: string | symbol) => void;
|
|
214
|
+
/**
|
|
215
|
+
* 表示参数装饰器
|
|
216
|
+
*/
|
|
217
|
+
type ParameterDecorator = (target: object, propertyKey: string | symbol | undefined, parameterIndex: number) => void;
|
|
218
|
+
/**
|
|
219
|
+
* 表示事件处理函数
|
|
220
|
+
* @template T - 事件数据类型
|
|
221
|
+
*/
|
|
222
|
+
type EventHandler<T = unknown> = (event: T) => void;
|
|
223
|
+
/**
|
|
224
|
+
* 表示事件监听器配置
|
|
225
|
+
* @template T - 事件数据类型
|
|
226
|
+
*/
|
|
227
|
+
interface EventListener<T = unknown> {
|
|
228
|
+
handler: EventHandler<T>;
|
|
229
|
+
once: boolean;
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* 表示可以取消订阅的订阅
|
|
233
|
+
*/
|
|
234
|
+
interface Subscription {
|
|
235
|
+
unsubscribe: () => void;
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* 为名义类型创建品牌类型
|
|
239
|
+
* @template T - 基础类型
|
|
240
|
+
* @template Brand - 品牌标识符
|
|
241
|
+
*/
|
|
242
|
+
type Brand<T, Brand extends string> = T & {
|
|
243
|
+
readonly __brand: Brand;
|
|
244
|
+
};
|
|
245
|
+
/**
|
|
246
|
+
* 表示正数
|
|
247
|
+
*/
|
|
248
|
+
type PositiveNumber = Brand<number, 'PositiveNumber'>;
|
|
249
|
+
/**
|
|
250
|
+
* 表示非空字符串
|
|
251
|
+
*/
|
|
252
|
+
type NonEmptyString = Brand<string, 'NonEmptyString'>;
|
|
253
|
+
/**
|
|
254
|
+
* 表示有效的电子邮件字符串
|
|
255
|
+
*/
|
|
256
|
+
type Email = Brand<string, 'Email'>;
|
|
257
|
+
/**
|
|
258
|
+
* 表示有效的 UUID 字符串
|
|
259
|
+
*/
|
|
260
|
+
type UUID = Brand<string, 'UUID'>;
|
|
261
|
+
/**
|
|
262
|
+
* 提取函数的返回类型
|
|
263
|
+
* @template T - 函数类型
|
|
264
|
+
*/
|
|
265
|
+
type ReturnTypeOf<T> = T extends (...args: unknown[]) => infer R ? R : never;
|
|
266
|
+
/**
|
|
267
|
+
* 将函数的参数提取为元组
|
|
268
|
+
* @template T - 函数类型
|
|
269
|
+
*/
|
|
270
|
+
type ParametersOf<T> = T extends (...args: infer P) => unknown ? P : never;
|
|
271
|
+
/**
|
|
272
|
+
* 使所有属性可变(移除 readonly)
|
|
273
|
+
* @template T - 要设为可变的类型
|
|
274
|
+
*/
|
|
275
|
+
type Mutable<T> = {
|
|
276
|
+
-readonly [P in keyof T]: T[P];
|
|
277
|
+
};
|
|
278
|
+
/**
|
|
279
|
+
* 表示可序列化为 JSON 的值
|
|
280
|
+
*/
|
|
281
|
+
type JsonValue = string | number | boolean | null | JsonObject | JsonArray;
|
|
282
|
+
/**
|
|
283
|
+
* 表示 JSON 对象
|
|
284
|
+
*/
|
|
285
|
+
interface JsonObject {
|
|
286
|
+
[key: string]: JsonValue;
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* 表示 JSON 数组
|
|
290
|
+
*/
|
|
291
|
+
type JsonArray = JsonValue[];
|
|
292
|
+
|
|
293
|
+
export type { AnyFunction as A, BinaryFunction as B, Constructor as C, Deferred as D, Err as E, NonEmptyString as F, Email as G, Head as H, UUID as I, ReturnTypeOf as J, Keys as K, ParametersOf as L, Mapper as M, Nullable as N, Optional as O, Primitive as P, Mutable as Q, Reducer as R, Some as S, Thunk as T, UnaryFunction as U, Values as V, JsonValue as W, JsonObject as X, JsonArray as Y, Predicate as a, Comparator as b, CurriedBinaryFunction as c, Ok as d, Result as e, None as f, Option as g, AsyncFunction as h, AsyncThunk as i, Dictionary as j, DeepPartial as k, DeepReadonly as l, RequiredKeys as m, OptionalKeys as n, Pair as o, Triple as p, Tail as q, ClassDecorator as r, MethodDecorator as s, PropertyDecorator as t, ParameterDecorator as u, EventHandler as v, EventListener as w, Subscription as x, Brand as y, PositiveNumber as z };
|
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Melange 库的核心类型定义
|
|
3
|
+
* @module melange/types
|
|
4
|
+
* @description 全面的 TypeScript 类型定义,支持函数式编程、
|
|
5
|
+
* 面向对象模式和 Melange 库的工具类型。
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* 表示可为空的类型,可以是类型 T 或 null/undefined
|
|
9
|
+
* @template T - 基础类型
|
|
10
|
+
*/
|
|
11
|
+
type Nullable<T> = T | null | undefined;
|
|
12
|
+
/**
|
|
13
|
+
* 表示可选类型,可以是类型 T 或 undefined
|
|
14
|
+
* @template T - 基础类型
|
|
15
|
+
*/
|
|
16
|
+
type Optional<T> = T | undefined;
|
|
17
|
+
/**
|
|
18
|
+
* 表示原始 JavaScript 类型
|
|
19
|
+
*/
|
|
20
|
+
type Primitive = string | number | boolean | symbol | bigint | null | undefined;
|
|
21
|
+
/**
|
|
22
|
+
* 表示任何函数类型
|
|
23
|
+
*/
|
|
24
|
+
type AnyFunction = (...args: unknown[]) => unknown;
|
|
25
|
+
/**
|
|
26
|
+
* 表示构造函数类型
|
|
27
|
+
* @template T - 实例类型
|
|
28
|
+
*/
|
|
29
|
+
type Constructor<T = object> = new (...args: unknown[]) => T;
|
|
30
|
+
/**
|
|
31
|
+
* 表示不接受参数并返回值的函数
|
|
32
|
+
* @template T - 返回类型
|
|
33
|
+
*/
|
|
34
|
+
type Thunk<T> = () => T;
|
|
35
|
+
/**
|
|
36
|
+
* 表示返回布尔值的谓词函数
|
|
37
|
+
* @template T - 输入类型
|
|
38
|
+
*/
|
|
39
|
+
type Predicate<T> = (value: T) => boolean;
|
|
40
|
+
/**
|
|
41
|
+
* 表示从类型 A 到类型 B 的映射函数
|
|
42
|
+
* @template A - 输入类型
|
|
43
|
+
* @template B - 输出类型
|
|
44
|
+
*/
|
|
45
|
+
type Mapper<A, B> = (value: A) => B;
|
|
46
|
+
/**
|
|
47
|
+
* 表示用于折叠/归约操作的归约函数
|
|
48
|
+
* @template T - 累加器类型
|
|
49
|
+
* @template U - 当前值类型
|
|
50
|
+
*/
|
|
51
|
+
type Reducer<T, U> = (accumulator: T, current: U) => T;
|
|
52
|
+
/**
|
|
53
|
+
* 表示用于排序的比较函数
|
|
54
|
+
* @template T - 被比较的类型
|
|
55
|
+
*/
|
|
56
|
+
type Comparator<T> = (a: T, b: T) => number;
|
|
57
|
+
/**
|
|
58
|
+
* 表示一元函数(单参数)
|
|
59
|
+
* @template A - 输入类型
|
|
60
|
+
* @template B - 输出类型
|
|
61
|
+
*/
|
|
62
|
+
type UnaryFunction<A, B> = (arg: A) => B;
|
|
63
|
+
/**
|
|
64
|
+
* 表示二元函数(两个参数)
|
|
65
|
+
* @template A - 第一个参数类型
|
|
66
|
+
* @template B - 第二个参数类型
|
|
67
|
+
* @template C - 返回类型
|
|
68
|
+
*/
|
|
69
|
+
type BinaryFunction<A, B, C> = (a: A, b: B) => C;
|
|
70
|
+
/**
|
|
71
|
+
* 表示柯里化的二元函数
|
|
72
|
+
* @template A - 第一个参数类型
|
|
73
|
+
* @template B - 第二个参数类型
|
|
74
|
+
* @template C - 返回类型
|
|
75
|
+
*/
|
|
76
|
+
type CurriedBinaryFunction<A, B, C> = (a: A) => (b: B) => C;
|
|
77
|
+
/**
|
|
78
|
+
* 表示成功的结果
|
|
79
|
+
* @template T - 成功值类型
|
|
80
|
+
*/
|
|
81
|
+
interface Ok<T> {
|
|
82
|
+
readonly _tag: 'Ok';
|
|
83
|
+
readonly value: T;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* 表示失败的结果
|
|
87
|
+
* @template E - 错误类型
|
|
88
|
+
*/
|
|
89
|
+
interface Err<E> {
|
|
90
|
+
readonly _tag: 'Err';
|
|
91
|
+
readonly error: E;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* 表示用于错误处理的 Result 类型
|
|
95
|
+
* @template T - 成功值类型
|
|
96
|
+
* @template E - 错误类型
|
|
97
|
+
*/
|
|
98
|
+
type Result<T, E> = Ok<T> | Err<E>;
|
|
99
|
+
/**
|
|
100
|
+
* 表示存在的值
|
|
101
|
+
* @template T - 值类型
|
|
102
|
+
*/
|
|
103
|
+
interface Some<T> {
|
|
104
|
+
readonly _tag: 'Some';
|
|
105
|
+
readonly value: T;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* 表示缺失的值
|
|
109
|
+
*/
|
|
110
|
+
interface None {
|
|
111
|
+
readonly _tag: 'None';
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* 表示用于可空值处理的 Option 类型
|
|
115
|
+
* @template T - 值类型
|
|
116
|
+
*/
|
|
117
|
+
type Option<T> = Some<T> | None;
|
|
118
|
+
/**
|
|
119
|
+
* 表示异步函数
|
|
120
|
+
* @template T - 返回类型
|
|
121
|
+
*/
|
|
122
|
+
type AsyncFunction<T> = (...args: unknown[]) => Promise<T>;
|
|
123
|
+
/**
|
|
124
|
+
* 表示异步 thunk
|
|
125
|
+
* @template T - 返回类型
|
|
126
|
+
*/
|
|
127
|
+
type AsyncThunk<T> = () => Promise<T>;
|
|
128
|
+
/**
|
|
129
|
+
* 表示可能已解析或未解析的延迟值
|
|
130
|
+
* @template T - 值类型
|
|
131
|
+
*/
|
|
132
|
+
interface Deferred<T> {
|
|
133
|
+
promise: Promise<T>;
|
|
134
|
+
resolve: (value: T) => void;
|
|
135
|
+
reject: (reason?: unknown) => void;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* 表示具有字符串键的记录
|
|
139
|
+
* @template T - 值类型
|
|
140
|
+
*/
|
|
141
|
+
type Dictionary<T> = Record<string, T>;
|
|
142
|
+
/**
|
|
143
|
+
* 表示深层部分类型
|
|
144
|
+
* @template T - 基础类型
|
|
145
|
+
*/
|
|
146
|
+
type DeepPartial<T> = T extends object ? {
|
|
147
|
+
[P in keyof T]?: DeepPartial<T[P]>;
|
|
148
|
+
} : T;
|
|
149
|
+
/**
|
|
150
|
+
* 表示深层只读类型
|
|
151
|
+
* @template T - 基础类型
|
|
152
|
+
*/
|
|
153
|
+
type DeepReadonly<T> = T extends object ? {
|
|
154
|
+
readonly [P in keyof T]: DeepReadonly<T[P]>;
|
|
155
|
+
} : T;
|
|
156
|
+
/**
|
|
157
|
+
* 使指定键变为必需
|
|
158
|
+
* @template T - 基础类型
|
|
159
|
+
* @template K - 要设为必需的键
|
|
160
|
+
*/
|
|
161
|
+
type RequiredKeys<T, K extends keyof T> = T & Required<Pick<T, K>>;
|
|
162
|
+
/**
|
|
163
|
+
* 使指定键变为可选
|
|
164
|
+
* @template T - 基础类型
|
|
165
|
+
* @template K - 要设为可选的键
|
|
166
|
+
*/
|
|
167
|
+
type OptionalKeys<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
168
|
+
/**
|
|
169
|
+
* 提取对象类型的键
|
|
170
|
+
* @template T - 对象类型
|
|
171
|
+
*/
|
|
172
|
+
type Keys<T> = keyof T;
|
|
173
|
+
/**
|
|
174
|
+
* 提取对象的值类型
|
|
175
|
+
* @template T - 对象类型
|
|
176
|
+
*/
|
|
177
|
+
type Values<T> = T[keyof T];
|
|
178
|
+
/**
|
|
179
|
+
* 表示一对值
|
|
180
|
+
* @template A - 第一个值类型
|
|
181
|
+
* @template B - 第二个值类型
|
|
182
|
+
*/
|
|
183
|
+
type Pair<A, B> = readonly [A, B];
|
|
184
|
+
/**
|
|
185
|
+
* 表示三元组值
|
|
186
|
+
* @template A - 第一个值类型
|
|
187
|
+
* @template B - 第二个值类型
|
|
188
|
+
* @template C - 第三个值类型
|
|
189
|
+
*/
|
|
190
|
+
type Triple<A, B, C> = readonly [A, B, C];
|
|
191
|
+
/**
|
|
192
|
+
* 提取元组的头部(第一个元素)
|
|
193
|
+
* @template T - 元组类型
|
|
194
|
+
*/
|
|
195
|
+
type Head<T extends readonly unknown[]> = T extends readonly [infer H, ...unknown[]] ? H : never;
|
|
196
|
+
/**
|
|
197
|
+
* 提取元组的尾部(除第一个元素外的所有元素)
|
|
198
|
+
* @template T - 元组类型
|
|
199
|
+
*/
|
|
200
|
+
type Tail<T extends readonly unknown[]> = T extends readonly [unknown, ...infer Rest] ? Rest : never;
|
|
201
|
+
/**
|
|
202
|
+
* 表示类装饰器
|
|
203
|
+
* @template T - 类类型
|
|
204
|
+
*/
|
|
205
|
+
type ClassDecorator<T extends Constructor> = (target: T) => T | void;
|
|
206
|
+
/**
|
|
207
|
+
* 表示方法装饰器
|
|
208
|
+
*/
|
|
209
|
+
type MethodDecorator = (target: object, propertyKey: string | symbol, descriptor: PropertyDescriptor) => PropertyDescriptor | void;
|
|
210
|
+
/**
|
|
211
|
+
* 表示属性装饰器
|
|
212
|
+
*/
|
|
213
|
+
type PropertyDecorator = (target: object, propertyKey: string | symbol) => void;
|
|
214
|
+
/**
|
|
215
|
+
* 表示参数装饰器
|
|
216
|
+
*/
|
|
217
|
+
type ParameterDecorator = (target: object, propertyKey: string | symbol | undefined, parameterIndex: number) => void;
|
|
218
|
+
/**
|
|
219
|
+
* 表示事件处理函数
|
|
220
|
+
* @template T - 事件数据类型
|
|
221
|
+
*/
|
|
222
|
+
type EventHandler<T = unknown> = (event: T) => void;
|
|
223
|
+
/**
|
|
224
|
+
* 表示事件监听器配置
|
|
225
|
+
* @template T - 事件数据类型
|
|
226
|
+
*/
|
|
227
|
+
interface EventListener<T = unknown> {
|
|
228
|
+
handler: EventHandler<T>;
|
|
229
|
+
once: boolean;
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* 表示可以取消订阅的订阅
|
|
233
|
+
*/
|
|
234
|
+
interface Subscription {
|
|
235
|
+
unsubscribe: () => void;
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* 为名义类型创建品牌类型
|
|
239
|
+
* @template T - 基础类型
|
|
240
|
+
* @template Brand - 品牌标识符
|
|
241
|
+
*/
|
|
242
|
+
type Brand<T, Brand extends string> = T & {
|
|
243
|
+
readonly __brand: Brand;
|
|
244
|
+
};
|
|
245
|
+
/**
|
|
246
|
+
* 表示正数
|
|
247
|
+
*/
|
|
248
|
+
type PositiveNumber = Brand<number, 'PositiveNumber'>;
|
|
249
|
+
/**
|
|
250
|
+
* 表示非空字符串
|
|
251
|
+
*/
|
|
252
|
+
type NonEmptyString = Brand<string, 'NonEmptyString'>;
|
|
253
|
+
/**
|
|
254
|
+
* 表示有效的电子邮件字符串
|
|
255
|
+
*/
|
|
256
|
+
type Email = Brand<string, 'Email'>;
|
|
257
|
+
/**
|
|
258
|
+
* 表示有效的 UUID 字符串
|
|
259
|
+
*/
|
|
260
|
+
type UUID = Brand<string, 'UUID'>;
|
|
261
|
+
/**
|
|
262
|
+
* 提取函数的返回类型
|
|
263
|
+
* @template T - 函数类型
|
|
264
|
+
*/
|
|
265
|
+
type ReturnTypeOf<T> = T extends (...args: unknown[]) => infer R ? R : never;
|
|
266
|
+
/**
|
|
267
|
+
* 将函数的参数提取为元组
|
|
268
|
+
* @template T - 函数类型
|
|
269
|
+
*/
|
|
270
|
+
type ParametersOf<T> = T extends (...args: infer P) => unknown ? P : never;
|
|
271
|
+
/**
|
|
272
|
+
* 使所有属性可变(移除 readonly)
|
|
273
|
+
* @template T - 要设为可变的类型
|
|
274
|
+
*/
|
|
275
|
+
type Mutable<T> = {
|
|
276
|
+
-readonly [P in keyof T]: T[P];
|
|
277
|
+
};
|
|
278
|
+
/**
|
|
279
|
+
* 表示可序列化为 JSON 的值
|
|
280
|
+
*/
|
|
281
|
+
type JsonValue = string | number | boolean | null | JsonObject | JsonArray;
|
|
282
|
+
/**
|
|
283
|
+
* 表示 JSON 对象
|
|
284
|
+
*/
|
|
285
|
+
interface JsonObject {
|
|
286
|
+
[key: string]: JsonValue;
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* 表示 JSON 数组
|
|
290
|
+
*/
|
|
291
|
+
type JsonArray = JsonValue[];
|
|
292
|
+
|
|
293
|
+
export type { AnyFunction as A, BinaryFunction as B, Constructor as C, Deferred as D, Err as E, NonEmptyString as F, Email as G, Head as H, UUID as I, ReturnTypeOf as J, Keys as K, ParametersOf as L, Mapper as M, Nullable as N, Optional as O, Primitive as P, Mutable as Q, Reducer as R, Some as S, Thunk as T, UnaryFunction as U, Values as V, JsonValue as W, JsonObject as X, JsonArray as Y, Predicate as a, Comparator as b, CurriedBinaryFunction as c, Ok as d, Result as e, None as f, Option as g, AsyncFunction as h, AsyncThunk as i, Dictionary as j, DeepPartial as k, DeepReadonly as l, RequiredKeys as m, OptionalKeys as n, Pair as o, Triple as p, Tail as q, ClassDecorator as r, MethodDecorator as s, PropertyDecorator as t, ParameterDecorator as u, EventHandler as v, EventListener as w, Subscription as x, Brand as y, PositiveNumber as z };
|