Skip to content
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

[Feature]: Adding generic type to DeferredData used by defer #9641

Closed
bennyk8y opened this issue Nov 27, 2022 · 4 comments
Closed

[Feature]: Adding generic type to DeferredData used by defer #9641

bennyk8y opened this issue Nov 27, 2022 · 4 comments
Labels

Comments

@bennyk8y
Copy link

bennyk8y commented Nov 27, 2022

What is the new or updated feature that you are suggesting?

When using defer in loader:

const loader = (client: QueryClient) => {
  return async () => {
    return defer({
        todos: fetch('https://jsonplaceholder.typicode.com/todos/1')
      });
  };
};

The data property returned by defer is Record<string, unknown> and cannot be typed properly:

 return defer({ todos: fetch('http://jsonplaceholder.com')}) as { data: { todos: { userId: number; id: number; title: string; } }}

will result an error Types of property 'data' are incompatible.

Allowing this syntax would solve it:

defer<{ userId: number; id: number; title: string; }>(fetch('https://jsonplaceholder.typicode.com/todos/1'));

and the return type of defer will be:

{ data: T } (where T is the generic)

Why should this feature be included?

Allowing proper typing for defer result.

@bennyk8y
Copy link
Author

#9642

@brophdawg11
Copy link
Contributor

I'm going to close this out and include it with #9641

@jgarplind
Copy link

I'm going to close this out and include it with #9641

Jumping between #9642 and this, it seems like the issue is unresolved?

FWIW, DeferredData typing is causing me similar typing trouble, and it would be helpful to understand if it something you acknowledge and plan to address, and if so where progress can be tracked (this issue would be a reasonable place in my opinion).

@brophdawg11
Copy link
Contributor

I must have pasted the wrong link - defer types should be done when we do the types for json, useLoaderData, etc. in this proposal: #9854

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants