tRPCttRPC
Powered by
AnonTGA
tRPC•2mo ago•
2 replies
AnonTG

How can I infer the trpc.procedure.mutationOptions type?

@trpc/client@trpc/react
Hi everyone.

I have this hook that uses the mutation options provided by tRPC. I want the end user to be able to pass the options for the mutation as well. How should I infer the type?

I'm using Node v24.11.1, tRPC v11.8.1 and the new TanStack React Query integration and everything is working fine, except for this issue that I'm stuck on.

I also saw the docs but they only work for the classic integration. The docs for the newer integration doesn't explain this issue.

export function useSomeHook({
    useMutationOptions
}: {
    useMutationOptions?: what should go here?
}) {
    const trpc = useTRPC()
    const result = useMutation(
                // Infer the type that goes in mutationOptions
        trpc.someProcedure.mutationOptions({...useMutationOptions})
    )

    return result
}
export function useSomeHook({
    useMutationOptions
}: {
    useMutationOptions?: what should go here?
}) {
    const trpc = useTRPC()
    const result = useMutation(
                // Infer the type that goes in mutationOptions
        trpc.someProcedure.mutationOptions({...useMutationOptions})
    )

    return result
}
tRPCJoin
Move Fast & Break Nothing. End-to-end typesafe APIs made easy.
5,015Members
Resources
Recent Announcements

Similar Threads

Was this page helpful?

Similar Threads

Infer the type of ctx for a specific procedure
iDarkLightningIiDarkLightning / ❓-help
4y ago
Finding the Unused TRPC procedure...
0xtz00xtz / ❓-help
11mo ago
tRPC middleware infer type from another protectedProcedure
TTT / ❓-help
3y ago