Get the inferred type of Variables from data provider
I want to access the typescript type of variables parameter from one of my data provider method update. However, refine does not seem automatically infer the type defined in useForm hook
2 Replies
Hi @TerryPan. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
To access the TypeScript type of the
variables
parameter from a data provider method like update
, you can use the GetVariables
utility type provided by refine. This utility type helps extract the type of variables from your queries or mutations.
Here's an example of how you can use GetVariables
to infer the type of the variables
parameter:
1. Define your mutation:
2. Generate the type for variables:
3. Use GetVariables
to convert it:
This will help you get the inferred type of the variables
parameter. You can then use this type in your useForm
hook or any other place where you need to specify the type of variables
.
For more information, you can refer to the GetVariables documentation (https://refine.dev/docs/data/packages/hasura/#getvariables).
If you need to use this in a useForm
hook, you can do something like this:
This ensures that the variables
parameter is correctly typed throughout your application.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@942599084726964264> kapa.ai is still learning and improving, please let us know how it did by reacting below