Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions packages/react-router/src/fileRoute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,7 @@ export class FileRoute<
TParentRoute,
TSearchSchemaUsed
>,
TFullSearchSchema extends
RouteConstraints['TFullSearchSchema'] = ResolveFullSearchSchema<
TParentRoute,
TSearchSchema
>,
TFullSearchSchema = ResolveFullSearchSchema<TParentRoute, TSearchSchema>,
TParams extends RouteConstraints['TParams'] = Expand<
Record<ParsePathParams<TPath>, string>
>,
Expand All @@ -184,9 +180,7 @@ export class FileRoute<
] extends [never]
? RouteContext
: TRouteContextReturn,
TAllContext extends Expand<
Assign<IsAny<TParentRoute['types']['allContext'], {}>, TRouteContext>
> = Expand<
TAllContext = Expand<
Assign<IsAny<TParentRoute['types']['allContext'], {}>, TRouteContext>
>,
TRouterContext extends RouteConstraints['TRouterContext'] = AnyContext,
Expand Down
99 changes: 41 additions & 58 deletions packages/react-router/src/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ export type RouteOptions<
TSearchSchema extends Record<string, any> = {},
TSearchSchemaUsed extends Record<string, any> = {},
TFullSearchSchemaInput extends Record<string, any> = TSearchSchemaUsed,
TFullSearchSchema extends Record<string, any> = TSearchSchema,
TFullSearchSchema = TSearchSchema,
TParams extends AnyPathParams = AnyPathParams,
TAllParams extends AnyPathParams = TParams,
TRouteContextReturn extends RouteContext = RouteContext,
TRouteContext extends RouteContext = RouteContext,
TRouterContext extends RouteConstraints['TRouterContext'] = AnyContext,
TAllContext extends Record<string, any> = AnyContext,
TAllContext = AnyContext,
TLoaderDeps extends Record<string, any> = {},
TLoaderDataReturn = unknown,
TLoaderData = [TLoaderDataReturn] extends [never]
Expand Down Expand Up @@ -107,13 +107,13 @@ export type FileBaseRouteOptions<
TPath extends string = string,
TSearchSchemaInput extends Record<string, any> = {},
TSearchSchema extends Record<string, any> = {},
TFullSearchSchema extends Record<string, any> = TSearchSchema,
TFullSearchSchema = TSearchSchema,
TParams extends AnyPathParams = {},
TAllParams = ParamsFallback<TPath, TParams>,
TRouteContextReturn extends RouteContext = RouteContext,
TRouteContext extends RouteContext = RouteContext,
TRouterContext extends RouteConstraints['TRouterContext'] = AnyContext,
TAllContext extends Record<string, any> = AnyContext,
TAllContext = AnyContext,
TLoaderDeps extends Record<string, any> = {},
TLoaderDataReturn = unknown,
> = {
Expand Down Expand Up @@ -173,13 +173,13 @@ export type BaseRouteOptions<
TSearchSchema extends Record<string, any> = {},
TSearchSchemaUsed extends Record<string, any> = {},
TFullSearchSchemaInput extends Record<string, any> = TSearchSchemaUsed,
TFullSearchSchema extends Record<string, any> = TSearchSchema,
TFullSearchSchema = TSearchSchema,
TParams extends AnyPathParams = {},
TAllParams = ParamsFallback<TPath, TParams>,
TRouteContextReturn extends RouteContext = RouteContext,
TRouteContext extends RouteContext = RouteContext,
TRouterContext extends RouteConstraints['TRouterContext'] = AnyContext,
TAllContext extends Record<string, any> = AnyContext,
TAllContext = AnyContext,
TLoaderDeps extends Record<string, any> = {},
TLoaderDataReturn = unknown,
> = RoutePathOptions<TCustomId, TPath> &
Expand All @@ -202,7 +202,7 @@ export type BaseRouteOptions<
}

type BeforeLoadFn<
TFullSearchSchema extends Record<string, any>,
TFullSearchSchema,
TParentRoute extends AnyRoute,
TAllParams,
TRouteContextReturn extends RouteContext,
Expand All @@ -222,7 +222,7 @@ type BeforeLoadFn<

export type UpdatableRouteOptions<
TAllParams extends Record<string, any>,
TFullSearchSchema extends Record<string, any>,
TFullSearchSchema,
TLoaderData,
> = {
// test?: (args: TAllContext) => void
Expand Down Expand Up @@ -325,7 +325,7 @@ export type SearchSchemaValidatorFn<TInput, TReturn> = (
export type RouteLoaderFn<
TAllParams = {},
TLoaderDeps extends Record<string, any> = {},
TAllContext extends Record<string, any> = AnyContext,
TAllContext = AnyContext,
TRouteContext extends Record<string, any> = AnyContext,
TLoaderData = unknown,
> = (
Expand All @@ -334,8 +334,8 @@ export type RouteLoaderFn<

export interface LoaderFnContext<
TAllParams = {},
TLoaderDeps extends Record<string, any> = {},
TAllContext extends Record<string, any> = AnyContext,
TLoaderDeps = {},
TAllContext = AnyContext,
TRouteContext extends Record<string, any> = AnyContext,
> {
abortController: AbortController
Expand Down Expand Up @@ -376,20 +376,27 @@ export type InferFullSearchSchemaInput<TRoute> = TRoute extends {
? TFullSearchSchemaInput
: {}

export type ResolveFullSearchSchema<TParentRoute, TSearchSchema> = Expand<
Assign<
Omit<InferFullSearchSchema<TParentRoute>, keyof RootSearchSchema>,
TSearchSchema
>
export type ResolveFullSearchSchema<
TParentRoute extends AnyRoute,
TSearchSchema,
> = Assign<
TParentRoute['isRoot'] extends true
? TParentRoute['types']['searchSchema']
: TParentRoute['types']['fullSearchSchema'],
TSearchSchema,
keyof RootSearchSchema
>

export type ResolveFullSearchSchemaInput<TParentRoute, TSearchSchemaUsed> =
Expand<
Assign<
Omit<InferFullSearchSchemaInput<TParentRoute>, keyof RootSearchSchema>,
TSearchSchemaUsed
>
>
export type ResolveFullSearchSchemaInput<
TParentRoute extends AnyRoute,
TSearchSchemaUsed,
> = Assign<
TParentRoute['isRoot'] extends true
? TParentRoute['types']['searchSchemaInput']
: TParentRoute['types']['fullSearchSchemaInput'],
TSearchSchemaUsed,
keyof RootSearchSchema
>

export interface AnyRoute
extends Route<
Expand Down Expand Up @@ -450,12 +457,9 @@ export type RouteConstraints = {
export function getRouteApi<
TId extends RouteIds<RegisteredRouter['routeTree']>,
TRoute extends AnyRoute = RouteById<RegisteredRouter['routeTree'], TId>,
TFullSearchSchema extends Record<
string,
any
> = TRoute['types']['fullSearchSchema'],
TFullSearchSchema = TRoute['types']['fullSearchSchema'],
TAllParams extends AnyPathParams = TRoute['types']['allParams'],
TAllContext extends Record<string, any> = TRoute['types']['allContext'],
TAllContext = TRoute['types']['allContext'],
TLoaderDeps extends Record<string, any> = TRoute['types']['loaderDeps'],
TLoaderData = TRoute['types']['loaderData'],
>(id: TId) {
Expand All @@ -473,12 +477,9 @@ export function getRouteApi<
export class RouteApi<
TId extends RouteIds<RegisteredRouter['routeTree']>,
TRoute extends AnyRoute = RouteById<RegisteredRouter['routeTree'], TId>,
TFullSearchSchema extends Record<
string,
any
> = TRoute['types']['fullSearchSchema'],
TFullSearchSchema = TRoute['types']['fullSearchSchema'],
TAllParams extends AnyPathParams = TRoute['types']['allParams'],
TAllContext extends Record<string, any> = TRoute['types']['allContext'],
TAllContext = TRoute['types']['allContext'],
TLoaderDeps extends Record<string, any> = TRoute['types']['loaderDeps'],
TLoaderData = TRoute['types']['loaderData'],
> {
Expand Down Expand Up @@ -568,11 +569,7 @@ export class Route<
string,
any
> = ResolveFullSearchSchemaInput<TParentRoute, TSearchSchemaUsed>,
TFullSearchSchema extends
RouteConstraints['TFullSearchSchema'] = ResolveFullSearchSchema<
TParentRoute,
TSearchSchema
>,
TFullSearchSchema = ResolveFullSearchSchema<TParentRoute, TSearchSchema>,
TParams extends RouteConstraints['TParams'] = Expand<
Record<ParsePathParams<TPath>, string>
>,
Expand All @@ -586,9 +583,7 @@ export class Route<
] extends [never]
? RouteContext
: TRouteContextReturn,
in out TAllContext extends Expand<
Assign<IsAny<TParentRoute['types']['allContext'], {}>, TRouteContext>
> = Expand<
in out TAllContext = Expand<
Assign<IsAny<TParentRoute['types']['allContext'], {}>, TRouteContext>
>,
TRouterContext extends RouteConstraints['TRouterContext'] = AnyContext,
Expand Down Expand Up @@ -918,11 +913,7 @@ export function createRoute<
string,
any
> = ResolveFullSearchSchemaInput<TParentRoute, TSearchSchemaUsed>,
TFullSearchSchema extends
RouteConstraints['TFullSearchSchema'] = ResolveFullSearchSchema<
TParentRoute,
TSearchSchema
>,
TFullSearchSchema = ResolveFullSearchSchema<TParentRoute, TSearchSchema>,
TParams extends RouteConstraints['TParams'] = Expand<
Record<ParsePathParams<TPath>, string>
>,
Expand All @@ -936,9 +927,7 @@ export function createRoute<
] extends [never]
? RouteContext
: TRouteContextReturn,
TAllContext extends Expand<
Assign<IsAny<TParentRoute['types']['allContext'], {}>, TRouteContext>
> = Expand<
TAllContext = Expand<
Assign<IsAny<TParentRoute['types']['allContext'], {}>, TRouteContext>
>,
TRouterContext extends RouteConstraints['TRouterContext'] = AnyContext,
Expand Down Expand Up @@ -1091,7 +1080,7 @@ export class RootRoute<
{}, // TAllParams
TRouteContextReturn, // TRouteContextReturn
TRouteContext, // TRouteContext
Expand<Assign<TRouterContext, TRouteContext>>, // TAllContext
Assign<TRouterContext, TRouteContext>, // TAllContext
TRouterContext, // TRouterContext
TLoaderDeps,
TLoaderDataReturn,
Expand Down Expand Up @@ -1298,16 +1287,10 @@ export class NotFoundRoute<
TParentRoute,
TSearchSchemaUsed
>,
TFullSearchSchema extends
RouteConstraints['TFullSearchSchema'] = ResolveFullSearchSchema<
TParentRoute,
TSearchSchema
>,
TFullSearchSchema = ResolveFullSearchSchema<TParentRoute, TSearchSchema>,
TRouteContextReturn extends RouteConstraints['TRouteContext'] = AnyContext,
TRouteContext extends RouteConstraints['TRouteContext'] = RouteContext,
TAllContext extends Expand<
Assign<IsAny<TParentRoute['types']['allContext'], {}>, TRouteContext>
> = Expand<
TAllContext = Expand<
Assign<IsAny<TParentRoute['types']['allContext'], {}>, TRouteContext>
>,
TRouterContext extends RouteConstraints['TRouterContext'] = AnyContext,
Expand Down
8 changes: 7 additions & 1 deletion packages/react-router/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,13 @@ export type IsUnion<T, U extends T = T> = (
? false
: true

export type Assign<TLeft, TRight> = Omit<TLeft, keyof TRight> & TRight
export type Assign<TLeft, TRight, TExclude = never> = {
[K in Exclude<keyof TLeft | keyof TRight, TExclude>]: K extends keyof TRight
? TRight[K]
: K extends keyof TLeft
? TLeft[K]
: never
}

export type Timeout = ReturnType<typeof setTimeout>

Expand Down