Repository: remix-run/react-router
File: packages/react-router/lib/router/define-route.ts (TypeScript)

Code before:
  response: ResponseStub;
};

// action
type ActionArgs<Param extends string> = {
  context: Context;
  request: Request;
  params: Params<Param>;
  response: ResponseStub;
};

// prettier-ignore
type Params<Param extends string> = Pretty<
  & {[key: string]: string | undefined}
  & {[K in Param as K extends `${string}?` ? never : K]: string}
  & {[K in Param as K extends `${infer P}?` ? P : never]?: string}
>

type IsDefined<T> = undefined extends T ? false : true;

// prettier-ignore
type _LoaderData<
  ServerLoaderData,
  ClientLoaderData,
  ClientLoaderHydrate extends boolean,
  HydrateFallback,
> = Awaited<
  [IsDefined<HydrateFallback>, ClientLoaderHydrate]  extends [true, true] ?
    IsDefined<ClientLoaderData> extends true ? ClientLoaderData :
    undefined
  :
  [IsDefined<ClientLoaderData>, IsDefined<ServerLoaderData>] extends [true, true] ? ServerLoaderData | ClientLoaderData :
  IsDefined<ClientLoaderData> extends true ?
    IsDefined<ClientLoaderHydrate> extends true ? ClientLoaderData :
    ClientLoaderData | undefined
  :
  IsDefined<ServerLoaderData> extends true ? ServerLoaderData :
  undefined
>

type LoaderData<
  ServerLoaderData,
  ClientLoaderData,
  ClientLoaderHydrate extends boolean,
  HydrateFallback
> = _LoaderData<
  Awaited<ServerLoaderData>,
  Awaited<ClientLoaderData>,
  ClientLoaderHydrate,
  HydrateFallback
>;

Review comment (suggestion):
Unlike for `Data` types (e.g. `ServerLoaderData`), its correct to check for `undefined extends` for `HydrateFallback` since `HydrateFallback` is a top-level value of `defineRoute` whereas the things like `ServerLoaderData` are inferred from the return type of a top-level value like `serverLoader`.

Code after:

// action
type ActionArgs<Param extends string> = {
  context: Context;
  request: Request;
  params: Params<Param>;
  response: ResponseStub;
};

// prettier-ignore
type Params<Param extends string> = Pretty<
  & {[key: string]: string | undefined}
  & {[K in Param as K extends `${string}?` ? never : K]: string}
  & {[K in Param as K extends `${infer P}?` ? P : never]?: string}
>

type IsDefined<T> = Equal<T, undefined> extends true ? false : true;

// prettier-ignore
type _LoaderData<
  ServerLoaderData,
  ClientLoaderData,
  ClientLoaderHydrate extends boolean,
  HydrateFallback,
> = Awaited<
  [undefined extends HydrateFallback ? false : true, ClientLoaderHydrate]  extends [true, true] ?
    IsDefined<ClientLoaderData> extends true ? ClientLoaderData :
    undefined
  :
  [IsDefined<ClientLoaderData>, IsDefined<ServerLoaderData>] extends [true, true] ? ServerLoaderData | ClientLoaderData :
  IsDefined<ClientLoaderData> extends true ?
    ClientLoaderHydrate extends true ? ClientLoaderData :
    ClientLoaderData | undefined
  :
  IsDefined<ServerLoaderData> extends true ? ServerLoaderData :
  undefined
>

type LoaderData<
  ServerLoaderData,
  ClientLoaderData,
  ClientLoaderHydrate extends boolean,
  HydrateFallback
> = _LoaderData<
  Awaited<ServerLoaderData>,
  Awaited<ClientLoaderData>,
  ClientLoaderHydrate,
  HydrateFallback
>;

// prettier-ignore