donavon / superjson-remix

MIT License
83 stars 4 forks source link

useLoaderData is not handling types correctly to infer typing from loader function #5

Open stefanwuest opened 1 year ago

stefanwuest commented 1 year ago

Automatic typing from the loader function by passing typeof loader to useLoaderData is not working with this package. It looks like useLoaderData is typed as:

export declare const useLoaderData: <Data>() => Data;

when it should be

export declare const useLoaderData: <Data>() => SerializeFrom<Data>;

to conform to how Remix types it.

Expected Behavior When using useLoaderData<typeof loader> where the loader function returns from the json function of this package, the types should be inferred correctly.

Soleone commented 10 months ago

I'm also struggling with this in Typescript at the moment:

image

Soleone commented 10 months ago

For what it's worth, I'm currently copy and pasting this code here to make it work in my project with superjson: https://github.com/kiliman/remix-superjson/blob/main/app/utils/data.ts