historyIntelli.ts 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. // @ts-nocheck
  2. // This file is generated by Umi automatically
  3. // DO NOT CHANGE IT MANUALLY!
  4. import { getRoutes } from './route'
  5. import type { History } from '/Users/kuns/ayftech/web/crazycharge-admin/node_modules/@umijs/renderer-react'
  6. type Routes = Awaited<ReturnType<typeof getRoutes>>['routes']
  7. type AllRoute = Routes[keyof Routes]
  8. type IsRoot<T extends any> = 'parentId' extends keyof T ? false : true
  9. // show `/` in not `layout / wrapper` only
  10. type GetAllRouteWithoutLayout<Item extends AllRoute> = Item extends any
  11. ? 'isWrapper' extends keyof Item
  12. ? never
  13. : 'isLayout' extends keyof Item
  14. ? never
  15. : Item
  16. : never
  17. type AllRouteWithoutLayout = GetAllRouteWithoutLayout<AllRoute>
  18. type IndexRoutePathname = '/' extends AllRouteWithoutLayout['path']
  19. ? '/'
  20. : never
  21. type GetChildrens<T extends any> = T extends any
  22. ? IsRoot<T> extends true
  23. ? never
  24. : T
  25. : never
  26. type Childrens = GetChildrens<AllRoute>
  27. type Root = Exclude<AllRoute, Childrens>
  28. type AllIds = AllRoute['id']
  29. type GetChildrensByParentId<
  30. Id extends AllIds,
  31. Item = AllRoute
  32. > = Item extends any
  33. ? 'parentId' extends keyof Item
  34. ? Item['parentId'] extends Id
  35. ? Item
  36. : never
  37. : never
  38. : never
  39. type RouteObject<
  40. Id extends AllIds,
  41. Item = GetChildrensByParentId<Id>
  42. > = IsNever<Item> extends true
  43. ? ''
  44. : Item extends AllRoute
  45. ? {
  46. [Key in Item['path'] as TrimSlash<Key>]: UnionMerge<
  47. RouteObject<Item['id']>
  48. >
  49. }
  50. : never
  51. type GetRootRouteObject<Item extends Root> = Item extends Root
  52. ? {
  53. [K in Item['path'] as TrimSlash<K>]: UnionMerge<RouteObject<Item['id']>>
  54. }
  55. : never
  56. type MergedResult = UnionMerge<GetRootRouteObject<Root>>
  57. // --- patch history types ---
  58. type HistoryTo = Parameters<History['push']>['0']
  59. type HistoryPath = Exclude<HistoryTo, string>
  60. type UmiPathname = Path<MergedResult> | (string & {})
  61. interface UmiPath extends HistoryPath {
  62. pathname: UmiPathname
  63. }
  64. type UmiTo = UmiPathname | UmiPath
  65. type UmiPush = (to: UmiTo, state?: any) => void
  66. type UmiReplace = (to: UmiTo, state?: any) => void
  67. export interface UmiHistory extends History {
  68. push: UmiPush
  69. replace: UmiReplace
  70. }
  71. // --- type utils ---
  72. type TrimLeftSlash<T extends string> = T extends `/${infer R}`
  73. ? TrimLeftSlash<R>
  74. : T
  75. type TrimRightSlash<T extends string> = T extends `${infer R}/`
  76. ? TrimRightSlash<R>
  77. : T
  78. type TrimSlash<T extends string> = TrimLeftSlash<TrimRightSlash<T>>
  79. type IsNever<T> = [T] extends [never] ? true : false
  80. type IsEqual<A, B> = (<G>() => G extends A ? 1 : 2) extends <G>() => G extends B
  81. ? 1
  82. : 2
  83. ? true
  84. : false
  85. type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (
  86. k: infer I
  87. ) => void
  88. ? I
  89. : never
  90. type UnionMerge<U> = UnionToIntersection<U> extends infer O
  91. ? { [K in keyof O]: O[K] }
  92. : never
  93. type ExcludeEmptyKey<T> = IsEqual<T, ''> extends true ? never : T
  94. type PathConcat<
  95. TKey extends string,
  96. TValue,
  97. N = TrimSlash<TKey>
  98. > = TValue extends string
  99. ? ExcludeEmptyKey<N>
  100. :
  101. | ExcludeEmptyKey<N>
  102. | `${N & string}${IsNever<ExcludeEmptyKey<N>> extends true
  103. ? ''
  104. : '/'}${UnionPath<TValue>}`
  105. type UnionPath<T> = {
  106. [K in keyof T]-?: PathConcat<K & string, T[K]>
  107. }[keyof T]
  108. type MakeSureLeftSlash<T> = T extends any
  109. ? `/${TrimRightSlash<T & string>}`
  110. : never
  111. // exclude `/*`, because it always at the top of the IDE tip list
  112. type Path<T, K = UnionPath<T>> = Exclude<MakeSureLeftSlash<K>, '/*'> | IndexRoutePathname