Skip to content

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

@bennyk8y

Description

@bennyk8y

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature-requestUsed to close PRs that haven't gone through/been accepted the Proposal process yet

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions