=
- RoutesPre[Id] extends { parentId: infer P extends RouteId } ?
- [...GetParents, P] :
- [];
-
-// prettier-ignore
-type _GetChildren = {
- [K in RouteId]: RoutesPre[K] extends { parentId : Id } ?
- RoutesPre[K] extends { index: true } ? [K] :
- RoutesPre[K] extends { path: undefined } ? [K, ...GetChildren] :
- [K] | [K, ...GetChildren]
- :
- []
-}[RouteId]
-
-type GetChildren = _GetChildren extends []
- ? []
- : Exclude<_GetChildren, []>;
-
-type GetBranch = [
- ...GetParents,
- Id,
- ...(RoutesPre[Id] extends { path: undefined }
- ? GetChildren
- : _GetChildren)
-];
-
-type Branches = {
- [Id in RouteId]: GetBranch;
-};
-
-type PartialParams = {
- [Id in RouteId]: RoutesPre[Id]["params"];
-};
-type BranchParams> = Branch extends [
- infer Id extends RouteId,
- ...infer Ids extends Array
-]
- ? PartialParams[Id] & BranchParams
- : {};
-export type Params = {
- [Id in RouteId]: Normalize>;
-};
diff --git a/packages/react-router/lib/types/register.ts b/packages/react-router/lib/types/register.ts
index 7c5f896756..a5bbd7f92b 100644
--- a/packages/react-router/lib/types/register.ts
+++ b/packages/react-router/lib/types/register.ts
@@ -5,5 +5,23 @@
* For more on declaration merging and module augmentation, see https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation .
*/
export interface Register {
- // params
+ // pages
+ // routeFiles
}
+
+// pages
+type AnyParams = Record;
+type AnyPages = Record;
+export type Pages = Register extends {
+ pages: infer Registered extends AnyPages;
+}
+ ? Registered
+ : AnyPages;
+
+// route files
+type AnyRouteFiles = Record;
+export type RouteFiles = Register extends {
+ routeFiles: infer Registered extends AnyRouteFiles;
+}
+ ? Registered
+ : AnyRouteFiles;
diff --git a/packages/react-router/lib/types/route-data.ts b/packages/react-router/lib/types/route-data.ts
index 9dc2b6b4da..c60e376939 100644
--- a/packages/react-router/lib/types/route-data.ts
+++ b/packages/react-router/lib/types/route-data.ts
@@ -4,6 +4,7 @@ import type {
} from "../dom/ssr/routeModules";
import type { DataWithResponseInit } from "../router/utils";
import type { Serializable } from "../server-runtime/single-fetch";
+import type { RouteModule } from "./route-module";
import type { unstable_SerializesTo } from "./serializes-to";
import type { Equal, Expect, Func, IsAny, Pretty } from "./utils";
@@ -67,7 +68,50 @@ export type SerializeFrom = T extends (...args: infer Args) => unknown
: ServerDataFrom
: T;
-// eslint-disable-next-line @typescript-eslint/no-unused-vars
+type IsDefined = Equal extends true ? false : true;
+
+// prettier-ignore
+type IsHydrate =
+ ClientLoader extends { hydrate: true } ? true :
+ ClientLoader extends { hydrate: false } ? false :
+ false
+
+export type GetLoaderData = _DataLoaderData<
+ ServerDataFrom,
+ ClientDataFrom,
+ IsHydrate,
+ T extends { HydrateFallback: Func } ? true : false
+>;
+
+// prettier-ignore
+type _DataLoaderData<
+ ServerLoaderData,
+ ClientLoaderData,
+ ClientLoaderHydrate extends boolean,
+ HasHydrateFallback
+> =
+ [HasHydrateFallback, ClientLoaderHydrate] extends [true, true] ?
+ IsDefined extends true ? ClientLoaderData :
+ undefined
+ :
+ [IsDefined, IsDefined] extends [true, true] ? ServerLoaderData | ClientLoaderData :
+ IsDefined extends true ? ClientLoaderData :
+ IsDefined extends true ? ServerLoaderData :
+ undefined
+
+export type GetActionData = _DataActionData<
+ ServerDataFrom,
+ ClientDataFrom
+>;
+
+// prettier-ignore
+type _DataActionData = Awaited<
+ [IsDefined, IsDefined] extends [true, true] ? ServerActionData | ClientActionData :
+ IsDefined extends true ? ClientActionData :
+ IsDefined extends true ? ServerActionData :
+ undefined
+>
+
type __tests = [
// ServerDataFrom
Expect, undefined>>,
@@ -130,5 +174,98 @@ type __tests = [
| { data: string; b: Date; c: () => boolean }
>
>,
- Expect { a: string } | Response>, { a: string }>>
+ Expect { a: string } | Response>, { a: string }>>,
+
+ // GetLoaderData
+ Expect, undefined>>,
+ Expect<
+ Equal<
+ GetLoaderData<{
+ loader: () => { a: string; b: Date; c: () => boolean };
+ }>,
+ { a: string; b: Date; c: undefined }
+ >
+ >,
+ Expect<
+ Equal<
+ GetLoaderData<{
+ clientLoader: () => { a: string; b: Date; c: () => boolean };
+ }>,
+ { a: string; b: Date; c: () => boolean }
+ >
+ >,
+ Expect<
+ Equal<
+ GetLoaderData<{
+ loader: () => { a: string; b: Date; c: () => boolean };
+ clientLoader: () => { d: string; e: Date; f: () => boolean };
+ }>,
+ | { a: string; b: Date; c: undefined }
+ | { d: string; e: Date; f: () => boolean }
+ >
+ >,
+ Expect<
+ Equal<
+ GetLoaderData<{
+ loader: () => { a: string; b: Date; c: () => boolean };
+ clientLoader: () => { d: string; e: Date; f: () => boolean };
+ HydrateFallback: () => unknown;
+ }>,
+ | { a: string; b: Date; c: undefined }
+ | { d: string; e: Date; f: () => boolean }
+ >
+ >,
+ Expect<
+ Equal<
+ GetLoaderData<{
+ loader: () => { a: string; b: Date; c: () => boolean };
+ clientLoader: (() => { d: string; e: Date; f: () => boolean }) & {
+ hydrate: true;
+ };
+ }>,
+ | { a: string; b: Date; c: undefined }
+ | { d: string; e: Date; f: () => boolean }
+ >
+ >,
+ Expect<
+ Equal<
+ GetLoaderData<{
+ loader: () => { a: string; b: Date; c: () => boolean };
+ clientLoader: (() => { d: string; e: Date; f: () => boolean }) & {
+ hydrate: true;
+ };
+ HydrateFallback: () => unknown;
+ }>,
+ { d: string; e: Date; f: () => boolean }
+ >
+ >,
+
+ // ActionData
+ Expect, undefined>>,
+ Expect<
+ Equal<
+ GetActionData<{
+ action: () => { a: string; b: Date; c: () => boolean };
+ }>,
+ { a: string; b: Date; c: undefined }
+ >
+ >,
+ Expect<
+ Equal<
+ GetActionData<{
+ clientAction: () => { a: string; b: Date; c: () => boolean };
+ }>,
+ { a: string; b: Date; c: () => boolean }
+ >
+ >,
+ Expect<
+ Equal<
+ GetActionData<{
+ action: () => { a: string; b: Date; c: () => boolean };
+ clientAction: () => { d: string; e: Date; f: () => boolean };
+ }>,
+ | { a: string; b: Date; c: undefined }
+ | { d: string; e: Date; f: () => boolean }
+ >
+ >
];
diff --git a/packages/react-router/lib/types/route-module-annotations.ts b/packages/react-router/lib/types/route-module-annotations.ts
new file mode 100644
index 0000000000..191ff35d16
--- /dev/null
+++ b/packages/react-router/lib/types/route-module-annotations.ts
@@ -0,0 +1,267 @@
+import type { MetaDescriptor } from "../dom/ssr/routeModules";
+import type { Location } from "../router/history";
+import type { LinkDescriptor } from "../router/links";
+import type {
+ unstable_MiddlewareNextFunction,
+ unstable_RouterContextProvider,
+} from "../router/utils";
+import type { AppLoadContext } from "../server-runtime/data";
+import type { MiddlewareEnabled } from "./future";
+
+import type { GetLoaderData, ServerDataFrom } from "./route-data";
+import type { RouteModule } from "./route-module";
+import type { Pretty } from "./utils";
+
+type MaybePromise = T | Promise;
+
+type Props = {
+ params: unknown;
+ loaderData: unknown;
+ actionData: unknown;
+};
+
+type RouteInfo = Props & {
+ module: RouteModule;
+ matches: Array;
+};
+
+type MatchInfo = {
+ id: string;
+ module: RouteModule;
+};
+
+type MetaMatch = Pretty<{
+ id: T["id"];
+ params: Record;
+ pathname: string;
+ meta: MetaDescriptor[];
+ data: GetLoaderData;
+ handle?: unknown;
+ error?: unknown;
+}>;
+
+// prettier-ignore
+type MetaMatches> =
+ T extends [infer F extends MatchInfo, ...infer R extends Array]
+ ? [MetaMatch, ...MetaMatches]
+ : Array | undefined>;
+
+type CreateMetaArgs = {
+ /** This is the current router `Location` object. This is useful for generating tags for routes at specific paths or query parameters. */
+ location: Location;
+ /** {@link https://reactrouter.com/start/framework/routing#dynamic-segments Dynamic route params} for the current route. */
+ params: T["params"];
+ /** The return value for this route's server loader function */
+ data: T["loaderData"] | undefined;
+ /** Thrown errors that trigger error boundaries will be passed to the meta function. This is useful for generating metadata for error pages. */
+ error?: unknown;
+ /** An array of the current {@link https://api.reactrouter.com/v7/interfaces/react_router.UIMatch.html route matches}, including parent route matches. */
+ matches: MetaMatches;
+};
+type MetaDescriptors = MetaDescriptor[];
+
+type HeadersArgs = {
+ loaderHeaders: Headers;
+ parentHeaders: Headers;
+ actionHeaders: Headers;
+ errorHeaders: Headers | undefined;
+};
+
+type ClientDataFunctionArgs = {
+ /**
+ * A {@link https://developer.mozilla.org/en-US/docs/Web/API/Request Fetch Request instance} which you can use to read the URL, the method, the "content-type" header, and the request body from the request.
+ *
+ * @note Because client data functions are called before a network request is made, the Request object does not include the headers which the browser automatically adds. React Router infers the "content-type" header from the enc-type of the form that performed the submission.
+ **/
+ request: Request;
+ /**
+ * {@link https://reactrouter.com/start/framework/routing#dynamic-segments Dynamic route params} for the current route.
+ * @example
+ * // app/routes.ts
+ * route("teams/:teamId", "./team.tsx"),
+ *
+ * // app/team.tsx
+ * export function clientLoader({
+ * params,
+ * }: Route.ClientLoaderArgs) {
+ * params.teamId;
+ * // ^ string
+ * }
+ **/
+ params: T["params"];
+ /**
+ * When `future.unstable_middleware` is not enabled, this is undefined.
+ *
+ * When `future.unstable_middleware` is enabled, this is an instance of
+ * `unstable_RouterContextProvider` and can be used to access context values
+ * from your route middlewares. You may pass in initial context values in your
+ * `` prop
+ */
+ context: unstable_RouterContextProvider;
+};
+
+type ServerDataFunctionArgs = {
+ /** A {@link https://developer.mozilla.org/en-US/docs/Web/API/Request Fetch Request instance} which you can use to read the url, method, headers (such as cookies), and request body from the request. */
+ request: Request;
+ /**
+ * {@link https://reactrouter.com/start/framework/routing#dynamic-segments Dynamic route params} for the current route.
+ * @example
+ * // app/routes.ts
+ * route("teams/:teamId", "./team.tsx"),
+ *
+ * // app/team.tsx
+ * export function loader({
+ * params,
+ * }: Route.LoaderArgs) {
+ * params.teamId;
+ * // ^ string
+ * }
+ **/
+ params: T["params"];
+ /**
+ * Without `future.unstable_middleware` enabled, this is the context passed in
+ * to your server adapter's `getLoadContext` function. It's a way to bridge the
+ * gap between the adapter's request/response API with your React Router app.
+ * It is only applicable if you are using a custom server adapter.
+ *
+ * With `future.unstable_middleware` enabled, this is an instance of
+ * `unstable_RouterContextProvider` and can be used for type-safe access to
+ * context value set in your route middlewares. If you are using a custom
+ * server adapter, you may provide an initial set of context values from your
+ * `getLoadContext` function.
+ */
+ context: MiddlewareEnabled extends true
+ ? unstable_RouterContextProvider
+ : AppLoadContext;
+};
+
+type CreateServerMiddlewareFunction = (
+ args: ServerDataFunctionArgs,
+ next: unstable_MiddlewareNextFunction
+) => MaybePromise;
+
+type CreateClientMiddlewareFunction = (
+ args: ClientDataFunctionArgs,
+ next: unstable_MiddlewareNextFunction
+) => MaybePromise;
+
+type CreateServerLoaderArgs = ServerDataFunctionArgs;
+
+type CreateClientLoaderArgs = ClientDataFunctionArgs & {
+ /** This is an asynchronous function to get the data from the server loader for this route. On client-side navigations, this will make a {@link https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API fetch} call to the React Router server loader. If you opt-into running your clientLoader on hydration, then this function will return the data that was already loaded on the server (via Promise.resolve). */
+ serverLoader: () => Promise>;
+};
+
+type CreateServerActionArgs = ServerDataFunctionArgs;
+
+type CreateClientActionArgs = ClientDataFunctionArgs & {
+ /** This is an asynchronous function that makes the {@link https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API fetch} call to the React Router server action for this route. */
+ serverAction: () => Promise>;
+};
+
+type CreateHydrateFallbackProps = {
+ params: T["params"];
+ loaderData?: T["loaderData"];
+ actionData?: T["actionData"];
+};
+
+type Match = Pretty<{
+ id: T["id"];
+ params: Record;
+ pathname: string;
+ data: GetLoaderData;
+ handle: unknown;
+}>;
+
+// prettier-ignore
+type Matches> =
+ T extends [infer F extends MatchInfo, ...infer R extends Array]
+ ? [Match, ...Matches]
+ : Array | undefined>;
+
+type CreateComponentProps = {
+ /**
+ * {@link https://reactrouter.com/start/framework/routing#dynamic-segments Dynamic route params} for the current route.
+ * @example
+ * // app/routes.ts
+ * route("teams/:teamId", "./team.tsx"),
+ *
+ * // app/team.tsx
+ * export default function Component({
+ * params,
+ * }: Route.ComponentProps) {
+ * params.teamId;
+ * // ^ string
+ * }
+ **/
+ params: T["params"];
+ /** The data returned from the `loader` or `clientLoader` */
+ loaderData: T["loaderData"];
+ /** The data returned from the `action` or `clientAction` following an action submission. */
+ actionData?: T["actionData"];
+ /** An array of the current {@link https://api.reactrouter.com/v7/interfaces/react_router.UIMatch.html route matches}, including parent route matches. */
+ matches: Matches;
+};
+
+type CreateErrorBoundaryProps = {
+ /**
+ * {@link https://reactrouter.com/start/framework/routing#dynamic-segments Dynamic route params} for the current route.
+ * @example
+ * // app/routes.ts
+ * route("teams/:teamId", "./team.tsx"),
+ *
+ * // app/team.tsx
+ * export function ErrorBoundary({
+ * params,
+ * }: Route.ErrorBoundaryProps) {
+ * params.teamId;
+ * // ^ string
+ * }
+ **/
+ params: T["params"];
+ error: unknown;
+ loaderData?: T["loaderData"];
+ actionData?: T["actionData"];
+};
+
+export type GetAnnotations = {
+ // links
+ LinkDescriptors: LinkDescriptor[];
+ LinksFunction: () => LinkDescriptor[];
+
+ // meta
+ MetaArgs: CreateMetaArgs;
+ MetaDescriptors: MetaDescriptors;
+ MetaFunction: (args: CreateMetaArgs) => MetaDescriptors;
+
+ // headers
+ HeadersArgs: HeadersArgs;
+ HeadersFunction: (args: HeadersArgs) => Headers | HeadersInit;
+
+ // middleware
+ unstable_MiddlewareFunction: CreateServerMiddlewareFunction;
+
+ // clientMiddleware
+ unstable_ClientMiddlewareFunction: CreateClientMiddlewareFunction;
+
+ // loader
+ LoaderArgs: CreateServerLoaderArgs;
+
+ // clientLoader
+ ClientLoaderArgs: CreateClientLoaderArgs;
+
+ // action
+ ActionArgs: CreateServerActionArgs;
+
+ // clientAction
+ ClientActionArgs: CreateClientActionArgs;
+
+ // HydrateFallback
+ HydrateFallbackProps: CreateHydrateFallbackProps;
+
+ // default (Component)
+ ComponentProps: CreateComponentProps;
+
+ // ErrorBoundary
+ ErrorBoundaryProps: CreateErrorBoundaryProps;
+};
diff --git a/packages/react-router/lib/types/route-module.ts b/packages/react-router/lib/types/route-module.ts
index ecb0495714..f2c4b1e35c 100644
--- a/packages/react-router/lib/types/route-module.ts
+++ b/packages/react-router/lib/types/route-module.ts
@@ -1,20 +1,6 @@
-import type { MetaDescriptor } from "../dom/ssr/routeModules";
-import type { Location } from "../router/history";
-import type { LinkDescriptor } from "../router/links";
-import type {
- unstable_MiddlewareNextFunction,
- unstable_RouterContextProvider,
-} from "../router/utils";
-import type { AppLoadContext } from "../server-runtime/data";
-import type { MiddlewareEnabled } from "./future";
+import type { Func } from "./utils";
-import type { ClientDataFrom, ServerDataFrom } from "./route-data";
-import type { Equal, Expect, Func, Pretty } from "./utils";
-
-type IsDefined = Equal extends true ? false : true;
-type MaybePromise = T | Promise;
-
-type RouteModule = {
+export type RouteModule = {
meta?: Func;
links?: Func;
headers?: Func;
@@ -27,385 +13,3 @@ type RouteModule = {
ErrorBoundary?: Func;
[key: string]: unknown; // allow user-defined exports
};
-
-type Props = {
- params: unknown;
- loaderData: unknown;
- actionData: unknown;
-};
-
-type RouteInfo = Props & {
- parents: Props[];
- module: RouteModule;
-};
-
-type MetaMatch = Pretty<
- Pick & {
- pathname: string;
- meta: MetaDescriptor[];
- data: T["loaderData"];
- handle?: unknown;
- error?: unknown;
- }
->;
-
-// prettier-ignore
-type MetaMatches =
- T extends [infer F extends Props, ...infer R extends Props[]]
- ? [MetaMatch, ...MetaMatches]
- : Array | undefined>;
-
-type CreateMetaArgs = {
- /** This is the current router `Location` object. This is useful for generating tags for routes at specific paths or query parameters. */
- location: Location;
- /** {@link https://reactrouter.com/start/framework/routing#dynamic-segments Dynamic route params} for the current route. */
- params: T["params"];
- /** The return value for this route's server loader function */
- data: T["loaderData"] | undefined;
- /** Thrown errors that trigger error boundaries will be passed to the meta function. This is useful for generating metadata for error pages. */
- error?: unknown;
- /** An array of the current {@link https://api.reactrouter.com/v7/interfaces/react_router.UIMatch.html route matches}, including parent route matches. */
- matches: MetaMatches<[...T["parents"], T]>;
-};
-type MetaDescriptors = MetaDescriptor[];
-
-type HeadersArgs = {
- loaderHeaders: Headers;
- parentHeaders: Headers;
- actionHeaders: Headers;
- errorHeaders: Headers | undefined;
-};
-
-// prettier-ignore
-type IsHydrate =
- ClientLoader extends { hydrate: true } ? true :
- ClientLoader extends { hydrate: false } ? false :
- false
-
-export type CreateLoaderData = _CreateLoaderData<
- ServerDataFrom,
- ClientDataFrom,
- IsHydrate,
- T extends { HydrateFallback: Func } ? true : false
->;
-
-// prettier-ignore
-type _CreateLoaderData<
- ServerLoaderData,
- ClientLoaderData,
- ClientLoaderHydrate extends boolean,
- HasHydrateFallback
-> =
- [HasHydrateFallback, ClientLoaderHydrate] extends [true, true] ?
- IsDefined extends true ? ClientLoaderData :
- undefined
- :
- [IsDefined, IsDefined] extends [true, true] ? ServerLoaderData | ClientLoaderData :
- IsDefined extends true ? ClientLoaderData :
- IsDefined extends true ? ServerLoaderData :
- undefined
-
-export type CreateActionData = _CreateActionData<
- ServerDataFrom,
- ClientDataFrom
->;
-
-// prettier-ignore
-type _CreateActionData = Awaited<
- [IsDefined, IsDefined] extends [true, true] ? ServerActionData | ClientActionData :
- IsDefined extends true ? ClientActionData :
- IsDefined extends true ? ServerActionData :
- undefined
->
-
-type ClientDataFunctionArgs = {
- /**
- * A {@link https://developer.mozilla.org/en-US/docs/Web/API/Request Fetch Request instance} which you can use to read the URL, the method, the "content-type" header, and the request body from the request.
- *
- * @note Because client data functions are called before a network request is made, the Request object does not include the headers which the browser automatically adds. React Router infers the "content-type" header from the enc-type of the form that performed the submission.
- **/
- request: Request;
- /**
- * {@link https://reactrouter.com/start/framework/routing#dynamic-segments Dynamic route params} for the current route.
- * @example
- * // app/routes.ts
- * route("teams/:teamId", "./team.tsx"),
- *
- * // app/team.tsx
- * export function clientLoader({
- * params,
- * }: Route.ClientLoaderArgs) {
- * params.teamId;
- * // ^ string
- * }
- **/
- params: T["params"];
- /**
- * This is a `RouterContextProvider` instance generated from your router's
- * `unstable_getContext` function and/or populated from route middleware
- * functions.
- */
- context: unstable_RouterContextProvider;
-};
-
-type ServerDataFunctionArgs = {
- /** A {@link https://developer.mozilla.org/en-US/docs/Web/API/Request Fetch Request instance} which you can use to read the url, method, headers (such as cookies), and request body from the request. */
- request: Request;
- /**
- * {@link https://reactrouter.com/start/framework/routing#dynamic-segments Dynamic route params} for the current route.
- * @example
- * // app/routes.ts
- * route("teams/:teamId", "./team.tsx"),
- *
- * // app/team.tsx
- * export function loader({
- * params,
- * }: Route.LoaderArgs) {
- * params.teamId;
- * // ^ string
- * }
- **/
- params: T["params"];
- /**
- * Without `future.unstable_middleware` enabled, this is the context passed in
- * to your server adapter's `getLoadContext` function. It's a way to bridge the
- * gap between the adapter's request/response API with your React Router app.
- * It is only applicable if you are using a custom server adapter.
- *
- * With `future.unstable_middleware` enabled, this is an instance of
- * `unstable_RouterContextProvider` and can be used for type-safe access to
- * context value set in your route middlewares. If you are using a custom
- * server adapter, you may provide an initial set of context values from your
- * `getLoadContext` function.
- */
- context: MiddlewareEnabled extends true
- ? unstable_RouterContextProvider
- : AppLoadContext;
-};
-
-type CreateServerMiddlewareFunction = (
- args: ServerDataFunctionArgs,
- next: unstable_MiddlewareNextFunction
-) => MaybePromise;
-
-type CreateClientMiddlewareFunction = (
- args: ClientDataFunctionArgs,
- next: unstable_MiddlewareNextFunction
-) => MaybePromise;
-
-type CreateServerLoaderArgs = ServerDataFunctionArgs;
-
-type CreateClientLoaderArgs = ClientDataFunctionArgs & {
- /** This is an asynchronous function to get the data from the server loader for this route. On client-side navigations, this will make a {@link https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API fetch} call to the React Router server loader. If you opt-into running your clientLoader on hydration, then this function will return the data that was already loaded on the server (via Promise.resolve). */
- serverLoader: () => Promise>;
-};
-
-type CreateServerActionArgs = ServerDataFunctionArgs;
-
-type CreateClientActionArgs = ClientDataFunctionArgs & {
- /** This is an asynchronous function that makes the {@link https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API fetch} call to the React Router server action for this route. */
- serverAction: () => Promise>;
-};
-
-type CreateHydrateFallbackProps = {
- params: T["params"];
- loaderData?: T["loaderData"];
- actionData?: T["actionData"];
-};
-
-type Match = Pretty<
- Pick & {
- pathname: string;
- data: T["loaderData"];
- handle: unknown;
- }
->;
-
-// prettier-ignore
-type Matches =
- T extends [infer F extends Props, ...infer R extends Props[]]
- ? [Match, ...Matches]
- : Array | undefined>;
-
-type CreateComponentProps = {
- /**
- * {@link https://reactrouter.com/start/framework/routing#dynamic-segments Dynamic route params} for the current route.
- * @example
- * // app/routes.ts
- * route("teams/:teamId", "./team.tsx"),
- *
- * // app/team.tsx
- * export default function Component({
- * params,
- * }: Route.ComponentProps) {
- * params.teamId;
- * // ^ string
- * }
- **/
- params: T["params"];
- /** The data returned from the `loader` or `clientLoader` */
- loaderData: T["loaderData"];
- /** The data returned from the `action` or `clientAction` following an action submission. */
- actionData?: T["actionData"];
- /** An array of the current {@link https://api.reactrouter.com/v7/interfaces/react_router.UIMatch.html route matches}, including parent route matches. */
- matches: Matches<[...T["parents"], T]>;
-};
-
-type CreateErrorBoundaryProps = {
- /**
- * {@link https://reactrouter.com/start/framework/routing#dynamic-segments Dynamic route params} for the current route.
- * @example
- * // app/routes.ts
- * route("teams/:teamId", "./team.tsx"),
- *
- * // app/team.tsx
- * export function ErrorBoundary({
- * params,
- * }: Route.ErrorBoundaryProps) {
- * params.teamId;
- * // ^ string
- * }
- **/
- params: T["params"];
- error: unknown;
- loaderData?: T["loaderData"];
- actionData?: T["actionData"];
-};
-
-export type RouteModuleAnnotations = {
- // links
- LinkDescriptors: LinkDescriptor[];
- LinksFunction: () => LinkDescriptor[];
-
- // meta
- MetaArgs: CreateMetaArgs;
- MetaDescriptors: MetaDescriptors;
- MetaFunction: (args: CreateMetaArgs) => MetaDescriptors;
-
- // headers
- HeadersArgs: HeadersArgs;
- HeadersFunction: (args: HeadersArgs) => Headers | HeadersInit;
-
- // middleware
- unstable_MiddlewareFunction: CreateServerMiddlewareFunction;
-
- // clientMiddleware
- unstable_ClientMiddlewareFunction: CreateClientMiddlewareFunction;
-
- // loader
- LoaderArgs: CreateServerLoaderArgs;
-
- // clientLoader
- ClientLoaderArgs: CreateClientLoaderArgs;
-
- // action
- ActionArgs: CreateServerActionArgs;
-
- // clientAction
- ClientActionArgs: CreateClientActionArgs;
-
- // HydrateFallback
- HydrateFallbackProps: CreateHydrateFallbackProps;
-
- // default (Component)
- ComponentProps: CreateComponentProps;
-
- // ErrorBoundary
- ErrorBoundaryProps: CreateErrorBoundaryProps;
-};
-
-// eslint-disable-next-line @typescript-eslint/no-unused-vars
-type __tests = [
- // LoaderData
- Expect, undefined>>,
- Expect<
- Equal<
- CreateLoaderData<{
- loader: () => { a: string; b: Date; c: () => boolean };
- }>,
- { a: string; b: Date; c: undefined }
- >
- >,
- Expect<
- Equal<
- CreateLoaderData<{
- clientLoader: () => { a: string; b: Date; c: () => boolean };
- }>,
- { a: string; b: Date; c: () => boolean }
- >
- >,
- Expect<
- Equal<
- CreateLoaderData<{
- loader: () => { a: string; b: Date; c: () => boolean };
- clientLoader: () => { d: string; e: Date; f: () => boolean };
- }>,
- | { a: string; b: Date; c: undefined }
- | { d: string; e: Date; f: () => boolean }
- >
- >,
- Expect<
- Equal<
- CreateLoaderData<{
- loader: () => { a: string; b: Date; c: () => boolean };
- clientLoader: () => { d: string; e: Date; f: () => boolean };
- HydrateFallback: () => unknown;
- }>,
- | { a: string; b: Date; c: undefined }
- | { d: string; e: Date; f: () => boolean }
- >
- >,
- Expect<
- Equal<
- CreateLoaderData<{
- loader: () => { a: string; b: Date; c: () => boolean };
- clientLoader: (() => { d: string; e: Date; f: () => boolean }) & {
- hydrate: true;
- };
- }>,
- | { a: string; b: Date; c: undefined }
- | { d: string; e: Date; f: () => boolean }
- >
- >,
- Expect<
- Equal<
- CreateLoaderData<{
- loader: () => { a: string; b: Date; c: () => boolean };
- clientLoader: (() => { d: string; e: Date; f: () => boolean }) & {
- hydrate: true;
- };
- HydrateFallback: () => unknown;
- }>,
- { d: string; e: Date; f: () => boolean }
- >
- >,
-
- // ActionData
- Expect, undefined>>,
- Expect<
- Equal<
- CreateActionData<{
- action: () => { a: string; b: Date; c: () => boolean };
- }>,
- { a: string; b: Date; c: undefined }
- >
- >,
- Expect<
- Equal<
- CreateActionData<{
- clientAction: () => { a: string; b: Date; c: () => boolean };
- }>,
- { a: string; b: Date; c: () => boolean }
- >
- >,
- Expect<
- Equal<
- CreateActionData<{
- action: () => { a: string; b: Date; c: () => boolean };
- clientAction: () => { d: string; e: Date; f: () => boolean };
- }>,
- | { a: string; b: Date; c: undefined }
- | { d: string; e: Date; f: () => boolean }
- >
- >
-];