From 54bb925f0fd14d5184a31f0fb5211fd99e9424db Mon Sep 17 00:00:00 2001 From: Pawel Paradysz Date: Thu, 24 Oct 2024 08:45:01 +0100 Subject: [PATCH] Update client.ts For some reason, type inference on this file fails during build step. Which means that if this code is put in a monorepo and becomes part of a package, the .d.ts file doesn't get generated, and when trpc is imported, the whole type inference gets lost. This little (mostly) documentation fix will ensure that people who come to tRPC-sveltekit, and copy code from the docs, will never encounter this issue. --- examples/simple/src/lib/trpc/client.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/examples/simple/src/lib/trpc/client.ts b/examples/simple/src/lib/trpc/client.ts index 6adff99..ff88464 100644 --- a/examples/simple/src/lib/trpc/client.ts +++ b/examples/simple/src/lib/trpc/client.ts @@ -1,9 +1,10 @@ import type { Router } from '$lib/trpc/router'; import { createTRPCClient, type TRPCClientInit } from 'trpc-sveltekit'; -let browserClient: ReturnType>; +type TRPCClient = ReturnType>; +let browserClient: TRPCClient; -export function trpc(init?: TRPCClientInit) { +export function trpc(init?: TRPCClientInit): TRPCClient { const isBrowser = typeof window !== 'undefined'; if (isBrowser && browserClient) return browserClient; const client = createTRPCClient({ init });