-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Single Fetch: missing type for useLoaderData<typeof clientLoader>() #9331
Comments
The reason is export function useLoaderData<T>(): T extends LoaderFunction_SingleFetch
? SingleFetchSerialize_V2<T>
: never;
export function useActionData<T>(): T extends ActionFunction_SingleFetch
? SingleFetchSerialize_V2<T>
: never;
type LoaderFunction_SingleFetch = (
args: LoaderFunctionArgs
) => Promise<DataFunctionReturnValue> | DataFunctionReturnValue;
type ActionFunction_SingleFetch = (
args: ActionFunctionArgs
) => Promise<DataFunctionReturnValue> | DataFunctionReturnValue; Extends for the generics of |
Possible fix: type ClientLoaderFunctionArgs_SingleFetch = Omit<
ClientLoaderFunctionArgs,
"serverLoader"
> & {
serverLoader: <T = AppData>() => ReturnType<T>;
};
type ClientLoaderFunction_SingleFetch = ((
args: ClientLoaderFunctionArgs_SingleFetch,
) => ReturnType<LoaderFunction_SingleFetch>) & {
hydrate?: boolean;
};
type ClientActionFunctionArgs_SingleFetch = Omit<
ClientActionFunctionArgs,
"serverLoader"
> & {
serverLoader: <T = AppData>() => ReturnType<T>;
};
type ClientActionFunction_SingleFetch = (
args: ActionLoaderFunctionArgs_SingleFetch,
) => ReturnType<ActionFunction_SingleFetch>; Then, add it on hooks type SingleFetchSerialize_V2<T extends LoaderFunction_SingleFetch | ActionFunction_SingleFetch | ClientLoaderFunction_SingleFetch | ClientActionFunction_SingleFetch> =
Awaited<ReturnType<T>> extends TypedDeferredData<infer D> ? D :
Awaited<ReturnType<T>> extends TypedResponse<Record<string, unknown>> ? SerializeFrom<T> :
Awaited<ReturnType<T>>;
declare module "@remix-run/react" {
export function useLoaderData<T>(): T extends
| LoaderFunction_SingleFetch
| ClientLoaderFunction_SingleFetch
? SingleFetchSerialize_V2<T>
: never;
export function useActionData<T>(): T extends
| ActionFunction_SingleFetch
| ClientActionFunction_SingleFetch
? SingleFetchSerialize_V2<T>
: never;
export function useRouteLoaderData<T>(
routeId: string,
): T extends LoaderFunction_SingleFetch | ClientLoaderFunction_SingleFetch
? SingleFetchSerialize_V2<T>
: never;
export function useFetcher<TData = unknown>(
opts?: Parameters<typeof useFetcherRR>[0],
): FetcherWithComponents<
TData extends
| LoaderFunction_SingleFetch
| ActionFunction_SingleFetch
| ClientLoaderFunction_SingleFetch
| ClientActionFunction_SingleFetch
? SingleFetchSerialize_V2<TData>
: never
>;
} |
Yeah, there will always be some friction when adding future API without breaking the existing types. At least TypeScript has a way to override these type definitions. In addition, I think Remix needs to add ones for the updated |
This should be resolved by the introduction of |
This fix is available in |
|
Reproduction
https://stackblitz.com/edit/remix-run-remix-43pane?file=app%2Froutes%2F_index.tsx
clientLoaderData
System Info
Used Package Manager
npm
Expected Behavior
useLoaderData<typeof clientLoader>();
should be typed.Actual Behavior
useLoaderData<typeof clientLoader>();
is of typenever
The text was updated successfully, but these errors were encountered: