LukasL
tRPC13mo ago
1 reply
Lukas

Can I get a mutations input type form my client?

Hey friends, I'm working on an angular app with tanstack query and trpc. I'm trying to solve duplication and have one central repository (service) of query options. For this I am using a service and it would be amazing to get the input type for my procedures.
@Injectable({
  providedIn: 'root',
})
export class QueriesService {
  private queryClient = inject(QueryClient);
  private trpcClient = injectTrpcClient();

  public createTemplate(input: any) {
    return () =>
      mutationOptions({
        mutationFn: () =>
          this.trpcClient.templateCategories.create.mutate(input),
        onSuccess: () => {
          this.queryClient.invalidateQueries({
            queryKey: ['templateCategories'],
          });
        },
      });
  }
}

You can see that I'd love to use the input type where I currently have
any
. Looking forward to your input.

EDIT: Okay I found AppRouter['templateCategories']['create']['_def']['$types']['input'] but that does not seem very nice 😅
Was this page helpful?