mutation typing #1601
Unanswered
hyusetiawan
asked this question in
Q&A
mutation typing
#1601
Replies: 2 comments 7 replies
-
I call
and the error message is : |
Beta Was this translation helpful? Give feedback.
0 replies
-
You'll need to explicitly type the callback from the 2nd parameter and on, those types will be inferred in the returning mutation function. There are two common styles to type it: Direct importsimport { type Mutation, type Variables } from './gqty';
const [login, mutationStates] = useMutation((mutation, args: Variables<Mutation["login"]>) => {
const token = mutation.login(args);
return token;
});
// Later in your code
<Button onClick={() => {
login({ username, password });
}}>Login</Button> Curated inputsconst [login, mutationStates] = useMutation((mutation, username: string, password: string) => {
const token = mutation.login({ username, password });
return token;
});
// Later in your code
<Button onClick={() => {
login(username, password);
}}>Login</Button> |
Beta Was this translation helpful? Give feedback.
7 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
im following the mutation for reach as shown here: https://gqty.dev/guides/react/write
but I am not getting the typing when I call the returned mutation function, like so:
![Screenshot 2023-08-26 at 1 59 37 PM](https://private-user-images.githubusercontent.com/1062920/263496932-f285eca9-74b9-4e27-a149-08dce0fbbabe.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk2Nzk2NDksIm5iZiI6MTczOTY3OTM0OSwicGF0aCI6Ii8xMDYyOTIwLzI2MzQ5NjkzMi1mMjg1ZWNhOS03NGI5LTRlMjctYTE0OS0wOGRjZTBmYmJhYmUucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI1MDIxNiUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNTAyMTZUMDQxNTQ5WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9MTc5MTlmYWZkOTQ5NzA5ZjBlNjBjOWRlZmQxNWNiNTlhZDhkYTU2NjM3N2IzZDVkMWU1MDY3Y2NmNDQ1YzE5YyZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.Rz0aQKVwVuOo1lRE2oVdG7wDQKXX5dBORYfC1aLj-FI)
![Screenshot 2023-08-26 at 1 59 09 PM](https://private-user-images.githubusercontent.com/1062920/263496921-e387fbc1-fc5b-4bec-8d2c-2f2b8ac3e08e.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk2Nzk2NDksIm5iZiI6MTczOTY3OTM0OSwicGF0aCI6Ii8xMDYyOTIwLzI2MzQ5NjkyMS1lMzg3ZmJjMS1mYzViLTRiZWMtOGQyYy0yZjJiOGFjM2UwOGUucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI1MDIxNiUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNTAyMTZUMDQxNTQ5WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9YTk0YjM1N2JmMjViYWVkOGEyNDljZDExM2VjNzhmODIyNjhhYzVjYmRlYmMwMzcyMjFhNjFkZWY4MGU5NGIyYiZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.AaYn9X-1-RZIsWtXredDtDFJSk9zR0101D5XiumvjYU)
but inside the callback, I am able to see the typing properly:
is there a way to type the
login
function?Beta Was this translation helpful? Give feedback.
All reactions