utils.ts 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /**
  2. * 任意类型的异步函数
  3. */
  4. type AnyPromiseFunction = (...arg: any[]) => PromiseLike<any>;
  5. /**
  6. * 任意类型的普通函数
  7. */
  8. type AnyNormalFunction = (...arg: any[]) => any;
  9. /**
  10. * 任意类型的函数
  11. */
  12. type AnyFunction = AnyNormalFunction | AnyPromiseFunction;
  13. /**
  14. * T | null 包装
  15. */
  16. type Nullable<T> = T | null;
  17. /**
  18. * T | Not null 包装
  19. */
  20. type NonNullable<T> = T extends null | undefined ? never : T;
  21. /**
  22. * 字符串类型对象
  23. */
  24. type Recordable<T = any> = Record<string, T>;
  25. /**
  26. * 字符串类型对象(只读)
  27. */
  28. interface ReadonlyRecordable<T = any> {
  29. readonly [key: string]: T;
  30. }
  31. /**
  32. * setTimeout 返回值类型
  33. */
  34. type TimeoutHandle = ReturnType<typeof setTimeout>;
  35. /**
  36. * setInterval 返回值类型
  37. */
  38. type IntervalHandle = ReturnType<typeof setInterval>;
  39. export {
  40. type AnyFunction,
  41. type AnyNormalFunction,
  42. type AnyPromiseFunction,
  43. type IntervalHandle,
  44. type NonNullable,
  45. type Nullable,
  46. type ReadonlyRecordable,
  47. type Recordable,
  48. type TimeoutHandle,
  49. };