@tanstack/react-router 1.27.0 → 1.28.1

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.
package/src/routeInfo.ts CHANGED
@@ -4,7 +4,7 @@ import type { Expand, UnionToIntersection, UnionToTuple } from './utils'
4
4
  export type ParseRoute<TRouteTree, TAcc = TRouteTree> = TRouteTree extends {
5
5
  types: { children: infer TChildren }
6
6
  }
7
- ? TChildren extends Array<unknown>
7
+ ? TChildren extends ReadonlyArray<unknown>
8
8
  ? ParseRoute<TChildren[number], TAcc | TChildren[number]>
9
9
  : TAcc
10
10
  : TAcc
@@ -14,7 +14,7 @@ export type RoutesById<TRouteTree extends AnyRoute> = {
14
14
  }
15
15
 
16
16
  export type RouteById<TRouteTree extends AnyRoute, TId> = Extract<
17
- Extract<ParseRoute<TRouteTree>, { id: TId }>,
17
+ RoutesById<TRouteTree>[TId],
18
18
  AnyRoute
19
19
  >
20
20
 
@@ -56,11 +56,9 @@ type Reduce<TValue extends Array<any>, TResult = unknown> = TValue extends [
56
56
  : TResult
57
57
 
58
58
  export type FullSearchSchema<TRouteTree extends AnyRoute> = Partial<
59
- Expand<
60
- Reduce<UnionToTuple<ParseRoute<TRouteTree>['types']['fullSearchSchema']>>
61
- >
59
+ Reduce<UnionToTuple<ParseRoute<TRouteTree>['types']['fullSearchSchema']>>
62
60
  >
63
61
 
64
- export type AllParams<TRouteTree extends AnyRoute> = Expand<
65
- UnionToIntersection<ParseRoute<TRouteTree>['types']['allParams']>
62
+ export type AllParams<TRouteTree extends AnyRoute> = UnionToIntersection<
63
+ ParseRoute<TRouteTree>['types']['allParams']
66
64
  >
package/src/router.ts CHANGED
@@ -261,9 +261,9 @@ export function createRouter<
261
261
  }
262
262
 
263
263
  export class Router<
264
- TRouteTree extends AnyRoute = AnyRoute,
265
- TDehydrated extends Record<string, any> = Record<string, any>,
266
- TSerializedError extends Record<string, any> = Record<string, any>,
264
+ in out TRouteTree extends AnyRoute = AnyRoute,
265
+ in out TDehydrated extends Record<string, any> = Record<string, any>,
266
+ in out TSerializedError extends Record<string, any> = Record<string, any>,
267
267
  > {
268
268
  // Option-independent properties
269
269
  tempLocationKey: string | undefined = `${Math.round(
@@ -1268,8 +1268,8 @@ export class Router<
1268
1268
  preload: !!preload,
1269
1269
  context: parentContext,
1270
1270
  location,
1271
- navigate: (opts) =>
1272
- this.navigate({ ...opts, from: match.pathname } as any),
1271
+ navigate: (opts: any) =>
1272
+ this.navigate({ ...opts, from: match.pathname }),
1273
1273
  buildLocation: this.buildLocation,
1274
1274
  cause: preload ? 'preload' : match.cause,
1275
1275
  })) ?? ({} as any)
package/src/useParams.tsx CHANGED
@@ -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 as TParams) : match.params
25
25
  },
26
- })
26
+ }) as TSelected
27
27
  }
package/src/utils.ts CHANGED
@@ -15,12 +15,14 @@ export type PickRequired<T> = {
15
15
  }
16
16
 
17
17
  // from https://stackoverflow.com/a/76458160
18
- export type WithoutEmpty<T> = T extends T ? ({} extends T ? never : T) : never
18
+ export type WithoutEmpty<T> = T extends any ? ({} extends T ? never : T) : never
19
19
 
20
20
  // export type Expand<T> = T
21
21
  export type Expand<T> = T extends object
22
22
  ? T extends infer O
23
- ? { [K in keyof O]: O[K] }
23
+ ? O extends Function
24
+ ? O
25
+ : { [K in keyof O]: O[K] }
24
26
  : never
25
27
  : T
26
28
 
@@ -36,10 +38,12 @@ export type DeepPartial<T> = T extends object
36
38
  }
37
39
  : T
38
40
 
39
- // eslint-disable-next-line @typescript-eslint/naming-convention
40
- export type MakeDifferenceOptional<T, U> = Omit<U, keyof T> &
41
- Partial<Pick<U, keyof T & keyof U>> &
42
- PickRequired<Omit<U, keyof PickRequired<T>>>
41
+ export type MakeDifferenceOptional<TLeft, TRight> = Omit<
42
+ TRight,
43
+ keyof TLeft
44
+ > & {
45
+ [K in keyof TLeft & keyof TRight]?: TRight[K]
46
+ }
43
47
 
44
48
  // from https://stackoverflow.com/a/53955431
45
49
  // eslint-disable-next-line @typescript-eslint/naming-convention