Giter VIP home page Giter VIP logo

Comments (9)

alvinvin00 avatar alvinvin00 commented on July 16, 2024 2

Hi @diegods-ferreira Please where does MutationFnType come from?

that's a generic

from bulletproof-react.

diegods-ferreira avatar diegods-ferreira commented on July 16, 2024 1

I really would like that too. I'm now having a really hard time trying to adapt those type declarations to React Query V4 =/

from bulletproof-react.

diegods-ferreira avatar diegods-ferreira commented on July 16, 2024 1

Hi @diegods-ferreira Please where does MutationFnType come from?

that's a generic

That's right

from bulletproof-react.

tripol avatar tripol commented on July 16, 2024 1

Thanks @alvinvin00 @diegods-ferreira

from bulletproof-react.

klevytskyi avatar klevytskyi commented on July 16, 2024 1

For those struggling like me. Leaving here another variation of MutationConfig compatible with react-query 4+, typescript 5.1+ and no-args mutation functions support.

type Fn = (...args: any[]) => any;

type GetTVariables<T> = T extends (...args: infer R) => any ? (R extends [infer TVar, ...any] ? TVar : void) : never;

export type MutationConfig<MutationFnType extends Fn> = UseMutationOptions<
  ExtractFnReturnType<Awaited<ReturnType<MutationFnType>>>,
  AxiosError,
  GetTVariables<MutationFnType>
>;

from bulletproof-react.

kbzowski avatar kbzowski commented on July 16, 2024

+1
Also would be great if I could set onError(error: AxiosError) for QueryConfig. Only onError(error: any) works

from bulletproof-react.

diegods-ferreira avatar diegods-ferreira commented on July 16, 2024

For anyone who would like to know, I was able to adapt the MutationConfig type to work with React Query v4. It is like this now:

import { AxiosError } from 'axios';
import { QueryClient, UseQueryOptions, UseMutationOptions, DefaultOptions } from '@tanstack/react-query';
import { AsyncReturnType } from 'type-fest';

...

type Fn = (...args: any) => any;

export type MutationConfig<MutationFnType extends Fn> = UseMutationOptions<
  ExtractFnReturnType<AsyncReturnType<MutationFnType>>,
  AxiosError,
  Parameters<MutationFnType>[0]
>;

from bulletproof-react.

tripol avatar tripol commented on July 16, 2024

Hi @diegods-ferreira Please where does MutationFnType come from?

from bulletproof-react.

galih56 avatar galih56 commented on July 16, 2024

Hi @diegods-ferreira Please where does MutationFnType come from?

that's a generic

What do you mean by generic?

from bulletproof-react.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.