-
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
Type mismatch when returning from useLoaderData #8874
Comments
Experiencing the same issues. |
i generally have to do |
It's one of the reasons I created |
@kiliman great that you've created the repo, I'll check it out. But I think this is a core Remix issue, isn't it? |
@iampeter I think any framework that serializes to JSON from server to client will have this issue. I believe once Remix supports RSC, they'll be able to stream native types to the client, and this will no longer be an issue. |
we are not talking about serialization of types, but about what type useLoaderData returns. it works correctly
|
import { useLoaderData } from "@remix-run/react"
export const useCustomLoaderData = <T extends (...args: any) => any>() => {
return useLoaderData() as Awaited<ReturnType<T>>
} |
I've noticed a related issue declare const x: JsonifyObject<{
foo: unknown;
}>;
// foo?: unknown
x.foo
declare const x: JsonifyObject<{
foo: string;
}>;
// foo: string
x.foo |
I'd like to drop an explanation why this happens for those that don't understand. It might help working around or fixing the issue. While you can return any expression from a Here a demo of the issue: TS Playground @ananevam you've mentioned, that the type comes from So there are currently a couple of ways to solve the issue (they are all not optimal).
As @kiliman mentioned, in the next BIG remix update we will be able to transfer data more complex than simple JSON and you won't have the issue. But meanwhile... We need to bite the dust. I'm also experience the issue and its annoying. @Magellol I can explain, why |
Reproduction
When strictNullChecks is disabled, if all fields within a field are optional, then the parent field itself becomes optional. This is due to wrapping the returned result in a JsonifyObject.
Sorry for my bad English.
playground
System Info
Used Package Manager
npm
Expected Behavior
types are the same
Actual Behavior
types don't match
The text was updated successfully, but these errors were encountered: