bill92
bill924mo ago

Infer query type of `data`

Using trpc version 11, how can I infer data?
const { isLoading, isError, error, data } =
trpc.patient.list.useQuery();

<SomeComponent data={data} />
const { isLoading, isError, error, data } =
trpc.patient.list.useQuery();

<SomeComponent data={data} />
Are there any utils on doing so? I've seen export type PatientData = inferRouterOutputs<ApiRouter>; but it doesn't work any help?
1 Reply
bill92
bill92OP4mo ago
this worked
import type { inferRouterOutputs } from '@trpc/server';

import { ApiRouter } from '@trinu/api';

export type ListPatientsOutput =
inferRouterOutputs<ApiRouter>['patient']['list-patients'];

function Content({ data }: { data: ListPatientsOutput | undefined }) {
...
}
import type { inferRouterOutputs } from '@trpc/server';

import { ApiRouter } from '@trinu/api';

export type ListPatientsOutput =
inferRouterOutputs<ApiRouter>['patient']['list-patients'];

function Content({ data }: { data: ListPatientsOutput | undefined }) {
...
}

Did you find this page helpful?