10dada08654539bdb44441d481e5c3042c3ee128ff56fee52b78fbe86edd7b6250e46c490edb500fd186a7114e58c96514a634d4a0e2d0cab165d366493405 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. export declare const mutable: <T extends readonly any[] | Record<string, unknown>>(val: T) => Mutable<typeof val>;
  2. export type Mutable<T> = {
  3. -readonly [P in keyof T]: T[P];
  4. };
  5. export type HTMLElementCustomized<T> = HTMLElement & T;
  6. /**
  7. * @deprecated stop to use null
  8. * @see {@link https://github.com/sindresorhus/meta/discussions/7}
  9. */
  10. export type Nullable<T> = T | null;
  11. export type Arrayable<T> = T | T[];
  12. export type Awaitable<T> = Promise<T> | T;
  13. type Primitive = null | undefined | string | number | boolean | symbol | bigint;
  14. type BrowserNativeObject = Date | FileList | File | Blob | RegExp;
  15. /**
  16. * Check whether it is tuple
  17. *
  18. * 检查是否为元组
  19. *
  20. * @example
  21. * IsTuple<[1, 2, 3]> => true
  22. * IsTuple<Array[number]> => false
  23. */
  24. type IsTuple<T extends ReadonlyArray<any>> = number extends T['length'] ? false : true;
  25. /**
  26. * Array method key
  27. *
  28. * 数组方法键
  29. */
  30. type ArrayMethodKey = keyof any[];
  31. /**
  32. * Tuple index key
  33. *
  34. * 元组下标键
  35. *
  36. * @example
  37. * TupleKey<[1, 2, 3]> => '0' | '1' | '2'
  38. */
  39. type TupleKey<T extends ReadonlyArray<any>> = Exclude<keyof T, ArrayMethodKey>;
  40. /**
  41. * Array index key
  42. *
  43. * 数组下标键
  44. */
  45. type ArrayKey = number;
  46. /**
  47. * Helper type for recursively constructing paths through a type
  48. *
  49. * 用于通过一个类型递归构建路径的辅助类型
  50. */
  51. type PathImpl<K extends string | number, V> = V extends Primitive | BrowserNativeObject ? `${K}` : `${K}` | `${K}.${Path<V>}`;
  52. /**
  53. * Type which collects all paths through a type
  54. *
  55. * 通过一个类型收集所有路径的类型
  56. *
  57. * @see {@link FieldPath}
  58. */
  59. type Path<T> = T extends ReadonlyArray<infer V> ? IsTuple<T> extends true ? {
  60. [K in TupleKey<T>]-?: PathImpl<Exclude<K, symbol>, T[K]>;
  61. }[TupleKey<T>] : PathImpl<ArrayKey, V> : {
  62. [K in keyof T]-?: PathImpl<Exclude<K, symbol>, T[K]>;
  63. }[keyof T];
  64. /**
  65. * Type which collects all paths through a type
  66. *
  67. * 通过一个类型收集所有路径的类型
  68. *
  69. * @example
  70. * FieldPath<{ 1: number; a: number; b: string; c: { d: number; e: string }; f: [{ value: string }]; g: { value: string }[]; h: Date; i: FileList; j: File; k: Blob; l: RegExp }> => '1' | 'a' | 'b' | 'c' | 'f' | 'g' | 'c.d' | 'c.e' | 'f.0' | 'f.0.value' | 'g.number' | 'g.number.value' | 'h' | 'i' | 'j' | 'k' | 'l'
  71. */
  72. export type FieldPath<T> = T extends object ? Path<T> : never;
  73. export {};