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

Get rid of TData generic in query function declaration #283

Closed
yekver opened this issue Dec 15, 2021 · 3 comments · Fixed by #284
Closed

Get rid of TData generic in query function declaration #283

yekver opened this issue Dec 15, 2021 · 3 comments · Fixed by #284
Labels
enhancement New feature or request

Comments

@yekver
Copy link
Contributor

yekver commented Dec 15, 2021

Right now every query function has a possibility to have on overwritten return type by using a TData generic. There is the responsible code. This generic looks strange because query functions will always return the same data. Also there is another problem with this approach: typescript unable to calculate queries return type dynamically because there is no guarantee that they wasn't overwritten.

I think it should look like this:

return `const ${operationName} = (\n ${toObjectString(props, 'implementation')}\n ${
      isRequestOptions && isMutatorHasSecondArg
        ? `options?: SecondParameter<typeof ${mutator.name}>`
        : ''
    }) => {${bodyForm}
      return ${mutator.name}<${response.definition.success || 'unknown'}>(
      ${mutatorConfig},
      ${requestOptions});
    }
  `;
@anymaniax
Copy link
Collaborator

The TData is there to keep a part of the useQuery flexibility. The TQueryFnData which is the type return by the promise is not overridable.

@yekver
Copy link
Contributor Author

yekver commented Dec 16, 2021

Yeah, but we are talking about the axios generator, not about the react-query generator. In my project react-query is also used but we have a special typescript helpers overlay for it on top of the axios query functions.

To make this work right there should be a possibility for the typescript to infer the return type for the query function. Using generics with a default value we are loosing this option because there is no guarantee that generic wouldn't be redefined.

@anymaniax
Copy link
Collaborator

Hey @yekver, for the Axios generator I agree that it doesn't make sense

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

Successfully merging a pull request may close this issue.

2 participants