diff --git a/packages/remix-server-runtime/single-fetch.ts b/packages/remix-server-runtime/single-fetch.ts index e9298122a7b..c9fb98e2638 100644 --- a/packages/remix-server-runtime/single-fetch.ts +++ b/packages/remix-server-runtime/single-fetch.ts @@ -369,16 +369,25 @@ type DataFunctionReturnValue = | TypedDeferredData> | TypedResponse>; +type Unwrap = T extends TypedDeferredData< + infer D +> + ? D + : T extends TypedResponse> + ? SerializeFrom + : T extends DataWithResponseInit + ? D + : T; + // Backwards-compatible type for Remix v2 where json/defer still use the old types, // and only non-json/defer returns use the new types. This allows for incremental // migration of loaders to return naked objects. In the next major version, // json/defer will be removed so everything will use the new simplified typings. // prettier-ignore -export type Serialize = - Awaited> extends TypedDeferredData ? D : - Awaited> extends TypedResponse> ? SerializeFrom : - Awaited> extends DataWithResponseInit ? D : - Awaited>; +export type Serialize>> = + R extends DataFunctionReturnValue + ? Unwrap + : R; export type Loader = ( args: LoaderFunctionArgs