utils.ts 1022 字节
Newer Older
V
vben 已提交
1 2 3 4 5 6 7 8 9 10
/**
 * 任意类型的异步函数
 */
type AnyPromiseFunction = (...arg: any) => PromiseLike<any>;

/**
 * 任意类型的普通函数
 */
type AnyNormalFunction = (...arg: any) => any;

11 12 13 14 15
/**
 * 任意类型的函数
 */
type AnyFunction = AnyNormalFunction | AnyPromiseFunction;

V
vben 已提交
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
/**
 *  T | null 包装
 */
type Nullable<T> = T | null;

/**
 * T | Not null 包装
 */
type NonNullable<T> = T extends null | undefined ? never : T;

/**
 * 字符串类型对象
 */
type Recordable<T> = Record<string, T>;

/**
 * 字符串类型对象(只读)
 */
V
vben 已提交
34
interface ReadonlyRecordable<T = any> {
V
vben 已提交
35
  readonly [key: string]: T;
V
vben 已提交
36
}
V
vben 已提交
37

38 39 40 41 42 43 44 45 46 47
/**
 * setTimeout 返回值类型
 */
type TimeoutHandle = ReturnType<typeof setTimeout>;

/**
 * setInterval 返回值类型
 */
type IntervalHandle = ReturnType<typeof setInterval>;

V
vben 已提交
48 49 50
export {
  type AnyFunction,
  type AnyNormalFunction,
V
vben 已提交
51 52
  type AnyPromiseFunction,
  type IntervalHandle,
V
vben 已提交
53
  type NonNullable,
V
vben 已提交
54
  type Nullable,
V
vben 已提交
55
  type ReadonlyRecordable,
V
vben 已提交
56
  type Recordable,
57
  type TimeoutHandle,
V
vben 已提交
58
};