@tanstack/react-router 1.22.5 → 1.22.6

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.
Files changed (161) hide show
  1. package/dist/cjs/CatchBoundary.cjs +1 -2
  2. package/dist/cjs/CatchBoundary.cjs.map +1 -1
  3. package/dist/cjs/Matches.cjs +12 -18
  4. package/dist/cjs/Matches.cjs.map +1 -1
  5. package/dist/cjs/Matches.d.cts +15 -15
  6. package/dist/cjs/RouterProvider.cjs +16 -15
  7. package/dist/cjs/RouterProvider.cjs.map +1 -1
  8. package/dist/cjs/RouterProvider.d.cts +6 -6
  9. package/dist/cjs/awaited.cjs +1 -1
  10. package/dist/cjs/awaited.cjs.map +1 -1
  11. package/dist/cjs/awaited.d.cts +1 -1
  12. package/dist/cjs/defer.cjs.map +1 -1
  13. package/dist/cjs/fileRoute.cjs +1 -1
  14. package/dist/cjs/fileRoute.cjs.map +1 -1
  15. package/dist/cjs/fileRoute.d.cts +17 -17
  16. package/dist/cjs/lazyRouteComponent.cjs.map +1 -1
  17. package/dist/cjs/lazyRouteComponent.d.cts +1 -1
  18. package/dist/cjs/link.cjs +10 -11
  19. package/dist/cjs/link.cjs.map +1 -1
  20. package/dist/cjs/link.d.cts +16 -13
  21. package/dist/cjs/location.d.cts +2 -2
  22. package/dist/cjs/not-found.cjs.map +1 -1
  23. package/dist/cjs/not-found.d.cts +2 -2
  24. package/dist/cjs/path.cjs +2 -2
  25. package/dist/cjs/path.cjs.map +1 -1
  26. package/dist/cjs/path.d.cts +4 -4
  27. package/dist/cjs/qss.cjs +4 -3
  28. package/dist/cjs/qss.cjs.map +1 -1
  29. package/dist/cjs/redirects.cjs.map +1 -1
  30. package/dist/cjs/redirects.d.cts +5 -5
  31. package/dist/cjs/route.cjs.map +1 -1
  32. package/dist/cjs/route.d.cts +34 -36
  33. package/dist/cjs/routeInfo.d.cts +5 -5
  34. package/dist/cjs/router.cjs +63 -66
  35. package/dist/cjs/router.cjs.map +1 -1
  36. package/dist/cjs/router.d.cts +28 -28
  37. package/dist/cjs/routerContext.cjs +1 -1
  38. package/dist/cjs/routerContext.cjs.map +1 -1
  39. package/dist/cjs/routerContext.d.cts +1 -1
  40. package/dist/cjs/scroll-restoration.cjs +7 -9
  41. package/dist/cjs/scroll-restoration.cjs.map +1 -1
  42. package/dist/cjs/scroll-restoration.d.cts +1 -1
  43. package/dist/cjs/searchParams.cjs +10 -12
  44. package/dist/cjs/searchParams.cjs.map +1 -1
  45. package/dist/cjs/searchParams.d.cts +1 -1
  46. package/dist/cjs/useBlocker.cjs.map +1 -1
  47. package/dist/cjs/useBlocker.d.cts +2 -2
  48. package/dist/cjs/useNavigate.cjs +1 -1
  49. package/dist/cjs/useNavigate.cjs.map +1 -1
  50. package/dist/cjs/useNavigate.d.cts +4 -4
  51. package/dist/cjs/useParams.cjs +1 -1
  52. package/dist/cjs/useParams.cjs.map +1 -1
  53. package/dist/cjs/useParams.d.cts +5 -5
  54. package/dist/cjs/useRouteContext.cjs +1 -1
  55. package/dist/cjs/useRouteContext.cjs.map +1 -1
  56. package/dist/cjs/useRouteContext.d.cts +4 -4
  57. package/dist/cjs/useRouter.cjs.map +1 -1
  58. package/dist/cjs/useRouter.d.cts +2 -2
  59. package/dist/cjs/useRouterState.cjs.map +1 -1
  60. package/dist/cjs/useRouterState.d.cts +2 -2
  61. package/dist/cjs/useSearch.cjs +1 -1
  62. package/dist/cjs/useSearch.cjs.map +1 -1
  63. package/dist/cjs/useSearch.d.cts +4 -4
  64. package/dist/cjs/utils.cjs +2 -2
  65. package/dist/cjs/utils.cjs.map +1 -1
  66. package/dist/cjs/utils.d.cts +13 -11
  67. package/dist/esm/CatchBoundary.js +1 -2
  68. package/dist/esm/CatchBoundary.js.map +1 -1
  69. package/dist/esm/Matches.d.ts +15 -15
  70. package/dist/esm/Matches.js +12 -18
  71. package/dist/esm/Matches.js.map +1 -1
  72. package/dist/esm/RouterProvider.d.ts +6 -6
  73. package/dist/esm/RouterProvider.js +16 -15
  74. package/dist/esm/RouterProvider.js.map +1 -1
  75. package/dist/esm/awaited.d.ts +1 -1
  76. package/dist/esm/awaited.js +1 -1
  77. package/dist/esm/awaited.js.map +1 -1
  78. package/dist/esm/defer.js.map +1 -1
  79. package/dist/esm/fileRoute.d.ts +17 -17
  80. package/dist/esm/fileRoute.js +1 -1
  81. package/dist/esm/fileRoute.js.map +1 -1
  82. package/dist/esm/lazyRouteComponent.d.ts +1 -1
  83. package/dist/esm/lazyRouteComponent.js.map +1 -1
  84. package/dist/esm/link.d.ts +16 -13
  85. package/dist/esm/link.js +10 -11
  86. package/dist/esm/link.js.map +1 -1
  87. package/dist/esm/location.d.ts +2 -2
  88. package/dist/esm/not-found.d.ts +2 -2
  89. package/dist/esm/not-found.js.map +1 -1
  90. package/dist/esm/path.d.ts +4 -4
  91. package/dist/esm/path.js +2 -2
  92. package/dist/esm/path.js.map +1 -1
  93. package/dist/esm/qss.js +4 -3
  94. package/dist/esm/qss.js.map +1 -1
  95. package/dist/esm/redirects.d.ts +5 -5
  96. package/dist/esm/redirects.js.map +1 -1
  97. package/dist/esm/route.d.ts +34 -36
  98. package/dist/esm/route.js.map +1 -1
  99. package/dist/esm/routeInfo.d.ts +5 -5
  100. package/dist/esm/router.d.ts +28 -28
  101. package/dist/esm/router.js +63 -66
  102. package/dist/esm/router.js.map +1 -1
  103. package/dist/esm/routerContext.d.ts +1 -1
  104. package/dist/esm/routerContext.js +1 -1
  105. package/dist/esm/routerContext.js.map +1 -1
  106. package/dist/esm/scroll-restoration.d.ts +1 -1
  107. package/dist/esm/scroll-restoration.js +7 -9
  108. package/dist/esm/scroll-restoration.js.map +1 -1
  109. package/dist/esm/searchParams.d.ts +1 -1
  110. package/dist/esm/searchParams.js +10 -12
  111. package/dist/esm/searchParams.js.map +1 -1
  112. package/dist/esm/useBlocker.d.ts +2 -2
  113. package/dist/esm/useBlocker.js.map +1 -1
  114. package/dist/esm/useNavigate.d.ts +4 -4
  115. package/dist/esm/useNavigate.js +1 -1
  116. package/dist/esm/useNavigate.js.map +1 -1
  117. package/dist/esm/useParams.d.ts +5 -5
  118. package/dist/esm/useParams.js +1 -1
  119. package/dist/esm/useParams.js.map +1 -1
  120. package/dist/esm/useRouteContext.d.ts +4 -4
  121. package/dist/esm/useRouteContext.js +1 -1
  122. package/dist/esm/useRouteContext.js.map +1 -1
  123. package/dist/esm/useRouter.d.ts +2 -2
  124. package/dist/esm/useRouter.js.map +1 -1
  125. package/dist/esm/useRouterState.d.ts +2 -2
  126. package/dist/esm/useRouterState.js.map +1 -1
  127. package/dist/esm/useSearch.d.ts +4 -4
  128. package/dist/esm/useSearch.js +1 -1
  129. package/dist/esm/useSearch.js.map +1 -1
  130. package/dist/esm/utils.d.ts +13 -11
  131. package/dist/esm/utils.js +2 -2
  132. package/dist/esm/utils.js.map +1 -1
  133. package/package.json +3 -2
  134. package/src/CatchBoundary.tsx +1 -1
  135. package/src/Matches.tsx +41 -48
  136. package/src/RouterProvider.tsx +22 -16
  137. package/src/awaited.tsx +3 -3
  138. package/src/defer.ts +1 -0
  139. package/src/fileRoute.ts +53 -53
  140. package/src/history.ts +1 -1
  141. package/src/lazyRouteComponent.tsx +2 -1
  142. package/src/link.tsx +50 -42
  143. package/src/location.ts +2 -2
  144. package/src/not-found.tsx +3 -2
  145. package/src/path.ts +8 -8
  146. package/src/qss.ts +4 -5
  147. package/src/redirects.ts +5 -5
  148. package/src/route.ts +73 -67
  149. package/src/routeInfo.ts +8 -6
  150. package/src/router.ts +150 -145
  151. package/src/routerContext.tsx +2 -2
  152. package/src/scroll-restoration.tsx +9 -12
  153. package/src/searchParams.ts +11 -13
  154. package/src/useBlocker.tsx +3 -3
  155. package/src/useNavigate.tsx +7 -5
  156. package/src/useParams.tsx +6 -6
  157. package/src/useRouteContext.ts +7 -8
  158. package/src/useRouter.tsx +2 -2
  159. package/src/useRouterState.tsx +2 -2
  160. package/src/useSearch.tsx +7 -6
  161. package/src/utils.ts +36 -24
@@ -1,7 +1,7 @@
1
1
  import * as React from 'react'
2
- import { Router } from './router'
2
+ import type { Router } from './router'
3
3
 
4
- let routerContext = React.createContext<Router<any>>(null!)
4
+ const routerContext = React.createContext<Router<any>>(null!)
5
5
 
6
6
  export function getRouterContext() {
7
7
  if (typeof document === 'undefined') {
@@ -3,9 +3,10 @@ import * as React from 'react'
3
3
  const useLayoutEffect =
4
4
  typeof window !== 'undefined' ? React.useLayoutEffect : React.useEffect
5
5
 
6
- import { ParsedLocation } from './location'
7
6
  import { useRouter } from './useRouter'
8
- import { NonNullableUpdater, functionalUpdate } from './utils'
7
+ import { functionalUpdate } from './utils'
8
+ import type { ParsedLocation } from './location'
9
+ import type { NonNullableUpdater } from './utils'
9
10
 
10
11
  const windowKey = 'window'
11
12
  const delimiter = '___'
@@ -25,7 +26,7 @@ type Cache = {
25
26
 
26
27
  const sessionsStorage = typeof window !== 'undefined' && window.sessionStorage
27
28
 
28
- let cache: Cache = sessionsStorage
29
+ const cache: Cache = sessionsStorage
29
30
  ? (() => {
30
31
  const storageKey = 'tsr-scroll-restoration-v2'
31
32
 
@@ -56,9 +57,7 @@ export function useScrollRestoration(options?: ScrollRestorationOptions) {
56
57
  const getKey = options?.getKey || defaultGetKey
57
58
 
58
59
  const { history } = window
59
- if (history.scrollRestoration) {
60
- history.scrollRestoration = 'manual'
61
- }
60
+ history.scrollRestoration = 'manual'
62
61
 
63
62
  const onScroll = (event: Event) => {
64
63
  if (weakScrolledElements.has(event.target)) return
@@ -137,8 +136,6 @@ export function useScrollRestoration(options?: ScrollRestorationOptions) {
137
136
 
138
137
  router.resetNextScroll = true
139
138
 
140
- const getKey = options?.getKey || defaultGetKey
141
-
142
139
  const restoreKey = getKey(event.toLocation)
143
140
  let windowRestored = false
144
141
 
@@ -173,7 +170,7 @@ export function useScrollRestoration(options?: ScrollRestorationOptions) {
173
170
  unsubOnBeforeLoad()
174
171
  unsubOnResolved()
175
172
  }
176
- }, [])
173
+ }, [options?.getKey, router])
177
174
  }
178
175
 
179
176
  export function ScrollRestoration(props: ScrollRestorationOptions) {
@@ -196,7 +193,7 @@ export function useElementScrollRestoration(
196
193
  },
197
194
  ) {
198
195
  const router = useRouter()
199
- const getKey = options?.getKey || defaultGetKey
196
+ const getKey = options.getKey || defaultGetKey
200
197
 
201
198
  let elementSelector = ''
202
199
 
@@ -216,8 +213,8 @@ export function useElementScrollRestoration(
216
213
  }
217
214
 
218
215
  function getCssSelector(el: any): string {
219
- let path = [],
220
- parent
216
+ const path = []
217
+ let parent
221
218
  while ((parent = el.parentNode)) {
222
219
  path.unshift(
223
220
  `${el.tagName}:nth-child(${
@@ -1,5 +1,5 @@
1
1
  import { decode, encode } from './qss'
2
- import { AnySearchSchema } from './route'
2
+ import type { AnySearchSchema } from './route'
3
3
 
4
4
  export const defaultParseSearch = parseSearchWith(JSON.parse)
5
5
  export const defaultStringifySearch = stringifySearchWith(
@@ -13,10 +13,10 @@ export function parseSearchWith(parser: (str: string) => any) {
13
13
  searchStr = searchStr.substring(1)
14
14
  }
15
15
 
16
- let query: Record<string, unknown> = decode(searchStr)
16
+ const query: Record<string, unknown> = decode(searchStr)
17
17
 
18
18
  // Try to parse any query params that might be json
19
- for (let key in query) {
19
+ for (const key in query) {
20
20
  const value = query[key]
21
21
  if (typeof value === 'string') {
22
22
  try {
@@ -58,16 +58,14 @@ export function stringifySearchWith(
58
58
  return (search: Record<string, any>) => {
59
59
  search = { ...search }
60
60
 
61
- if (search) {
62
- Object.keys(search).forEach((key) => {
63
- const val = search[key]
64
- if (typeof val === 'undefined' || val === undefined) {
65
- delete search[key]
66
- } else {
67
- search[key] = stringifyValue(val)
68
- }
69
- })
70
- }
61
+ Object.keys(search).forEach((key) => {
62
+ const val = search[key]
63
+ if (typeof val === 'undefined' || val === undefined) {
64
+ delete search[key]
65
+ } else {
66
+ search[key] = stringifyValue(val)
67
+ }
68
+ })
71
69
 
72
70
  const searchStr = encode(search as Record<string, string>).toString()
73
71
 
@@ -1,7 +1,7 @@
1
1
  import * as React from 'react'
2
- import { ReactNode } from './route'
3
2
  import { useRouter } from './useRouter'
4
- import { BlockerFn } from '@tanstack/history'
3
+ import type { BlockerFn } from '@tanstack/history'
4
+ import type { ReactNode } from './route'
5
5
 
6
6
  export function useBlocker(
7
7
  blockerFn: BlockerFn,
@@ -17,7 +17,7 @@ export function useBlocker(
17
17
 
18
18
  export function Block({ blocker, condition, children }: PromptProps) {
19
19
  useBlocker(blocker, condition)
20
- return (children ?? null) as ReactNode
20
+ return children ?? null
21
21
  }
22
22
 
23
23
  export type PromptProps = {
@@ -1,10 +1,11 @@
1
1
  import * as React from 'react'
2
2
  import { useMatch } from './Matches'
3
3
  import { useRouter } from './useRouter'
4
- import { NavigateOptions } from './link'
5
- import { AnyRoute } from './route'
6
- import { RoutePaths, RoutePathsAutoComplete } from './routeInfo'
7
- import { RegisteredRouter } from './router'
4
+
5
+ import type { NavigateOptions } from './link'
6
+ import type { AnyRoute } from './route'
7
+ import type { RoutePaths, RoutePathsAutoComplete } from './routeInfo'
8
+ import type { RegisteredRouter } from './router'
8
9
 
9
10
  export type UseNavigateResult<TDefaultFrom extends string> = <
10
11
  TTo extends string,
@@ -28,7 +29,7 @@ export function useNavigate<
28
29
  (options: NavigateOptions) => {
29
30
  return router.navigate({
30
31
  ...options,
31
- from: options?.to ? router.state.resolvedLocation.pathname : undefined,
32
+ from: options.to ? router.state.resolvedLocation.pathname : undefined,
32
33
  })
33
34
  },
34
35
  [router],
@@ -65,6 +66,7 @@ export function Navigate<
65
66
  from: props.to ? match.pathname : undefined,
66
67
  ...props,
67
68
  } as any)
69
+ // eslint-disable-next-line react-hooks/exhaustive-deps
68
70
  }, [])
69
71
 
70
72
  return null
package/src/useParams.tsx CHANGED
@@ -1,9 +1,9 @@
1
- import { AnyRoute } from './route'
2
- import { RouteIds, RouteById, AllParams } from './routeInfo'
3
- import { RegisteredRouter } from './router'
4
- import { Expand } from './utils'
5
- import { StrictOrFrom } from './utils'
6
1
  import { useMatch } from './Matches'
2
+ import type { AnyRoute } from './route'
3
+ import type { AllParams, RouteById, RouteIds } from './routeInfo'
4
+ import type { RegisteredRouter } from './router'
5
+ import type { Expand } from './utils'
6
+ import type { StrictOrFrom } from './utils'
7
7
 
8
8
  export function useParams<
9
9
  TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],
@@ -21,7 +21,7 @@ export function useParams<
21
21
  return useMatch({
22
22
  ...opts,
23
23
  select: (match) => {
24
- return opts?.select ? opts.select(match.params) : match.params
24
+ return opts.select ? opts.select(match.params) : match.params
25
25
  },
26
26
  })
27
27
  }
@@ -1,8 +1,9 @@
1
- import { useMatch, RouteMatch } from './Matches'
2
- import { AnyRoute } from './route'
3
- import { RouteIds, RouteById } from './routeInfo'
4
- import { RegisteredRouter } from './router'
5
- import { StrictOrFrom } from './utils'
1
+ import { useMatch } from './Matches'
2
+ import type { RouteMatch } from './Matches'
3
+ import type { AnyRoute } from './route'
4
+ import type { RouteById, RouteIds } from './routeInfo'
5
+ import type { RegisteredRouter } from './router'
6
+ import type { StrictOrFrom } from './utils'
6
7
 
7
8
  export function useRouteContext<
8
9
  TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],
@@ -17,8 +18,6 @@ export function useRouteContext<
17
18
  return useMatch({
18
19
  ...(opts as any),
19
20
  select: (match: RouteMatch) =>
20
- opts?.select
21
- ? opts.select(match.context as TRouteContext)
22
- : match.context,
21
+ opts.select ? opts.select(match.context as TRouteContext) : match.context,
23
22
  })
24
23
  }
package/src/useRouter.tsx CHANGED
@@ -1,8 +1,8 @@
1
1
  import * as React from 'react'
2
2
  import warning from 'tiny-warning'
3
- import { AnyRoute } from './route'
4
- import { RegisteredRouter, Router } from './router'
5
3
  import { getRouterContext } from './routerContext'
4
+ import type { AnyRoute } from './route'
5
+ import type { RegisteredRouter, Router } from './router'
6
6
 
7
7
  export function useRouter<
8
8
  TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],
@@ -1,7 +1,7 @@
1
1
  import { useStore } from '@tanstack/react-store'
2
- import { AnyRoute } from './route'
3
- import { RegisteredRouter, Router, RouterState } from './router'
4
2
  import { useRouter } from './useRouter'
3
+ import type { AnyRoute } from './route'
4
+ import type { RegisteredRouter, Router, RouterState } from './router'
5
5
 
6
6
  export function useRouterState<
7
7
  TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],
package/src/useSearch.tsx CHANGED
@@ -1,9 +1,10 @@
1
- import { AnyRoute, RootSearchSchema } from './route'
2
- import { RouteIds, RouteById, FullSearchSchema } from './routeInfo'
3
- import { RegisteredRouter } from './router'
4
- import { RouteMatch } from './Matches'
5
1
  import { useMatch } from './Matches'
6
- import { Expand, StrictOrFrom } from './utils'
2
+ import { Expand } from './utils'
3
+ import type { AnyRoute, RootSearchSchema } from './route'
4
+ import type { FullSearchSchema, RouteById, RouteIds } from './routeInfo'
5
+ import type { RegisteredRouter } from './router'
6
+ import type { RouteMatch } from './Matches'
7
+ import type { StrictOrFrom } from './utils'
7
8
 
8
9
  export function useSearch<
9
10
  TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],
@@ -24,7 +25,7 @@ export function useSearch<
24
25
  return useMatch({
25
26
  ...opts,
26
27
  select: (match: RouteMatch) => {
27
- return opts?.select ? opts.select(match.search as TSearch) : match.search
28
+ return opts.select ? opts.select(match.search as TSearch) : match.search
28
29
  },
29
30
  })
30
31
  }
package/src/utils.ts CHANGED
@@ -1,9 +1,14 @@
1
1
  import * as React from 'react'
2
2
 
3
3
  export type NoInfer<T> = [T][T extends any ? 0 : never]
4
- export type IsAny<T, Y, N = T> = 1 extends 0 & T ? Y : N
5
- export type PickAsRequired<T, K extends keyof T> = Omit<T, K> &
6
- Required<Pick<T, K>>
4
+ export type IsAny<TValue, TYesResult, TNoResult = TValue> = 1 extends 0 & TValue
5
+ ? TYesResult
6
+ : TNoResult
7
+ export type PickAsRequired<TValue, TKey extends keyof TValue> = Omit<
8
+ TValue,
9
+ TKey
10
+ > &
11
+ Required<Pick<TValue, TKey>>
7
12
 
8
13
  export type PickRequired<T> = {
9
14
  [K in keyof T as undefined extends T[K] ? never : K]: T[K]
@@ -19,26 +24,25 @@ export type Expand<T> = T extends object
19
24
  : never
20
25
  : T
21
26
 
22
- export type UnionToIntersection<U> = (
23
- U extends any ? (k: U) => void : never
27
+ export type UnionToIntersection<T> = (
28
+ T extends any ? (k: T) => void : never
24
29
  ) extends (k: infer I) => any
25
30
  ? I
26
31
  : never
27
32
 
28
- export type DeepOptional<T, K extends keyof T> = Pick<DeepPartial<T>, K> &
29
- Omit<T, K>
30
-
31
33
  export type DeepPartial<T> = T extends object
32
34
  ? {
33
35
  [P in keyof T]?: DeepPartial<T[P]>
34
36
  }
35
37
  : T
36
38
 
39
+ // eslint-disable-next-line @typescript-eslint/naming-convention
37
40
  export type MakeDifferenceOptional<T, U> = Omit<U, keyof T> &
38
41
  Partial<Pick<U, keyof T & keyof U>> &
39
42
  PickRequired<Omit<U, keyof PickRequired<T>>>
40
43
 
41
44
  // from https://stackoverflow.com/a/53955431
45
+ // eslint-disable-next-line @typescript-eslint/naming-convention
42
46
  export type IsUnion<T, U extends T = T> = (
43
47
  T extends any ? (U extends T ? false : true) : never
44
48
  ) extends false
@@ -61,10 +65,13 @@ export type IsUnion<T, U extends T = T> = (
61
65
  // }
62
66
  // >
63
67
 
64
- export type Assign<Left, Right> = Omit<Left, keyof Right> & Right
68
+ export type Assign<TLeft, TRight> = Omit<TLeft, keyof TRight> & TRight
65
69
 
66
- export type AssignAll<T extends any[]> = T extends [infer Left, ...infer Right]
67
- ? Right extends any[]
70
+ export type AssignAll<T extends Array<any>> = T extends [
71
+ infer Left,
72
+ ...infer Right,
73
+ ]
74
+ ? Right extends Array<any>
68
75
  ? Assign<Left, AssignAll<Right>>
69
76
  : Left
70
77
  : {}
@@ -116,21 +123,21 @@ export type NonNullableUpdater<TPrevious, TResult = TPrevious> =
116
123
  | ((prev: TPrevious) => TResult)
117
124
 
118
125
  // from https://github.com/type-challenges/type-challenges/issues/737
119
- type LastInUnion<U> =
120
- UnionToIntersection<U extends unknown ? (x: U) => 0 : never> extends (
126
+ type LastInUnion<T> =
127
+ UnionToIntersection<T extends unknown ? (x: T) => 0 : never> extends (
121
128
  x: infer L,
122
129
  ) => 0
123
130
  ? L
124
131
  : never
125
- export type UnionToTuple<U, Last = LastInUnion<U>> = [U] extends [never]
132
+ export type UnionToTuple<T, TLast = LastInUnion<T>> = [T] extends [never]
126
133
  ? []
127
- : [...UnionToTuple<Exclude<U, Last>>, Last]
134
+ : [...UnionToTuple<Exclude<T, TLast>>, TLast]
128
135
 
129
136
  //
130
137
 
131
138
  export const isServer = typeof document === 'undefined'
132
139
 
133
- export function last<T>(arr: T[]) {
140
+ export function last<T>(arr: Array<T>) {
134
141
  return arr[arr.length - 1]
135
142
  }
136
143
 
@@ -143,14 +150,17 @@ export function functionalUpdate<TResult>(
143
150
  previous: TResult,
144
151
  ): TResult {
145
152
  if (isFunction(updater)) {
146
- return updater(previous as TResult)
153
+ return updater(previous)
147
154
  }
148
155
 
149
156
  return updater
150
157
  }
151
158
 
152
- export function pick<T, K extends keyof T>(parent: T, keys: K[]): Pick<T, K> {
153
- return keys.reduce((obj: any, key: K) => {
159
+ export function pick<TValue, TKey extends keyof TValue>(
160
+ parent: TValue,
161
+ keys: Array<TKey>,
162
+ ): Pick<TValue, TKey> {
163
+ return keys.reduce((obj: any, key: TKey) => {
154
164
  obj[key] = parent[key]
155
165
  return obj
156
166
  }, {} as any)
@@ -268,11 +278,13 @@ export function deepEqual(a: any, b: any, partial: boolean = false): boolean {
268
278
  return false
269
279
  }
270
280
 
271
- export function useStableCallback<T extends (...args: any[]) => any>(fn: T): T {
281
+ export function useStableCallback<T extends (...args: Array<any>) => any>(
282
+ fn: T,
283
+ ): T {
272
284
  const fnRef = React.useRef(fn)
273
285
  fnRef.current = fn
274
286
 
275
- const ref = React.useRef((...args: any[]) => fnRef.current(...args))
287
+ const ref = React.useRef((...args: Array<any>) => fnRef.current(...args))
276
288
  return ref.current as T
277
289
  }
278
290
 
@@ -295,10 +307,10 @@ export function shallow<T>(objA: T, objB: T) {
295
307
  return false
296
308
  }
297
309
 
298
- for (let i = 0; i < keysA.length; i++) {
310
+ for (const item of keysA) {
299
311
  if (
300
- !Object.prototype.hasOwnProperty.call(objB, keysA[i] as string) ||
301
- !Object.is(objA[keysA[i] as keyof T], objB[keysA[i] as keyof T])
312
+ !Object.prototype.hasOwnProperty.call(objB, item) ||
313
+ !Object.is(objA[item as keyof T], objB[item as keyof T])
302
314
  ) {
303
315
  return false
304
316
  }