I am working in a new Next JS project and running into an annoying typescript error that I am struggling to reconcile.
I have some data passing setup with TRPC as follows:
const { data: user, isLoading } = api.example.getAll.useQuery<User>(['getAll'], {
onSuccess(a) {
a ? setItems(a?.examples) : null
}
});
However, I am running into the following type error:
No overload matches this call.
Overload 1 of 2, '(input: void | undefined, opts: DefinedUseTRPCQueryOptions<"example.getAll", void | undefined, User, (User & { examples: Example[]; }) | null, TRPCClientErrorLike<BuildProcedure<"query", { _config: RootConfig<{ ctx: { session: Session | null; prisma: PrismaClient<...>; }; meta: object; errorShape: DefaultErrorShape; transformer: { ...; }; }>; ... 5 more ...; _meta: object; }, (User & { ...; }) | null>>>): DefinedUseTRPCQueryResult<...>', gave the following error.
Argument of type 'string[]' is not assignable to parameter of type 'void'.
Overload 2 of 2, '(input: void | undefined, opts?: UseTRPCQueryOptions<"example.getAll", void | undefined, User, (User & { examples: Example[]; }) | null, TRPCClientErrorLike<BuildProcedure<"query", { _config: RootConfig<{ ctx: { session: Session | null; prisma: PrismaClient<...>; }; meta: object; errorShape: DefaultErrorShape; transformer: { ...; }; }>; ... 5 more ...; _meta: object; }, (User & { ...; }) | null>>> | undefined): UseTRPCQueryResult<...>', gave the following error.
Argument of type 'string[]' is not assignable to parameter of type 'void'.ts(2769)
I believe this is due to the keyword in TRPC. As I am working on v10 of the library, I understood I could remove this but doing so:
const { data: user, isLoading } = api.example.getAll.useQuery<User>({
onSuccess(a) {
a ? setItems(a?.examples) : null
}
});
I run into a different error - also referencing 'void':
Argument of type '{ onSuccess(a: any): void; }' is not assignable to parameter of type 'void'.
Any ideas?