Closed SudoerWithAnOpinion closed 8 months ago
I think I ran into this problem at some point, You could try using superjson
import type { AppRouter } from '$core/api/root';
import type { QueryClient } from '@tanstack/svelte-query';
import type { inferRouterInputs, inferRouterOutputs } from '@trpc/server';
import superjson from 'superjson';
import { svelteQueryWrapper } from 'trpc-svelte-query-adapter';
import { type TRPCClientInit, createTRPCClient } from 'trpc-sveltekit';
let browserClient: ReturnType<typeof svelteQueryWrapper<AppRouter>>;
export function api(init?: TRPCClientInit, queryClient?: QueryClient) {
const isBrowser = typeof window !== 'undefined';
if (isBrowser && browserClient) return browserClient;
const client = svelteQueryWrapper<AppRouter>({
client: createTRPCClient<AppRouter>({ init, transformer: superjson, url: '/api/trpc' }),
queryClient
});
if (isBrowser) browserClient = client;
return client;
}
/**
* Inference helper for inputs
* @example type HelloInput = RouterInputs['example']['hello']
**/
export type RouterInputs = inferRouterInputs<AppRouter>;
/**
* Inference helper for outputs
* @example type HelloOutput = RouterOutputs['example']['hello']
**/
export type RouterOutputs = inferRouterOutputs<AppRouter>;
Superjson, or tRPC-Transformer if you're looking for a quick solution combining superjson with Decimal.js.
I have a single working procedure that uses Sequelize to query a database. When I call this procedure from a
+page.ts
, it has a typeof…Asset[]
, when I attempt to use the other one, it says its type isobject[]
instead ofAsset[]
.Below is the defined procedure, when I check the types on the procedures, they are correct.
Am I missing something critical? When I use the
router.createCaller(…)
pattern, it works fine. I am using the examples wheret.ts
handles initTRPC, must like the bookstall example. Thequery()
call is correctly returning the data I’d like from the DB, but typed asobject[]
is causing type errors and does break the entire point of using tRPC