JSON inferred router output not matching

Hello. I have a procedure query which is returning Json from a postgresql db using Prisma. The type in the query on the server is showing up as JsonValue (definitions below). The inferred type from the router.procedure.query() on a createTRPCProxyClient instance comes back as expected, but the type definition using inferRouterOutputs<AppRouter> types the Json data as string | null. Any ideas? Thanks. New to tRPC so sorry if this is a no-brainer.
type JsonObject = { [Key in string]?: JsonValue };
interface JsonArray extends Array<JsonValue> {}
type JsonValue = string | number | boolean | JsonObject | JsonArray | null;
type JsonObject = { [Key in string]?: JsonValue };
interface JsonArray extends Array<JsonValue> {}
type JsonValue = string | number | boolean | JsonObject | JsonArray | null;
N
Nick420d ago
Have you enabled strict mode in your tsconfig? You should use it everywhere in this ecosystem But JsonValue does declare null as a possible value there, are you sure that’s not it?
R
rd420d ago
Yes I believe strict is enabled everywhere
N
Nick420d ago
Is that type a special class type or just a typescript type?
R
rd420d ago
Hmm, I just reset my TS server and I think it's updated, my apologies. I think it may have been Prisma creating some kind of deeply recursive type that maybe the server wasn't dealing with for whatever reason? I'm seeing Type instantiation is excessively deep and possibly infinite. when I try to access that value now. So likely Prisma related and tRPC is doing everything correctly 👍 Thanks for your help and sorry for not trying that sooner
N
Nick420d ago
Ouch, that's not a good error though Usually means Typescript can't do typechecking on that type
More Posts
Best way to implement input based validation on a router procedureHi guys, bit of a noob. I have already created a 'protectedProcedure', ensuring the user is logged [Help] Turbo shared typesI have a turborepo with two apps (web and embed). web is a t3 stack and embed is a create-react-app.Cache SSG helper responseI'm using `createProxySSGHelpers` in GSSP with `ssr: false` in the global config. I trying to cacheInput is too big for a single dispatchI decided to try tRPC for my Crypto analytics dashboard. However, I'm having a hard time passing theHow to manage custom errors (e.g. custom error codes) in tRPC?What's the recommended way to add fields to a TRPCError? How do you make that typesafe also on the ctypesafe permissionsHi, So I wanted to infer all the procedures from my router recursively & assign a permission (stringawaiting for procedure & logging the response.Hi, I was wondering if there is a way to handle the return object via the post-middleware's? I know createCaller Dependency Injection in Middleware ctx ?`createCaller` makes it really easy to inject dependencies via anything that's created during the `cbest practices for organizing routes/procedures?i'm trying to find some practices/styles in which people generally define routes with trpc. currentlValidating input inside middleware declaration```js const enforceUserIsCreatorOfEvent = t.middleware(({ ctx, next, input }) => { if (!input.evenFetch errors on stale pagesRecently I have been getting a lot of fetch errors on stale pages, in particular ones that have querHow to use querykeys from react-queryI am trying to implement a search query to an api that i am fetching via a procedure, i also read onDistribute typesafe tRPC Client in an NPM libraryHi ! super fan of trpc over here. We are building a javascript sdk for our API that is essentiallyWebsocket is not defined errorI'm getting a "WebSocket is not defined error" on my next app connected to an express backend. Any i@trpc/server in a non-server environment Error in Azure CIIm trying to add vitest unit tests for my trpc procedures. I followed some examples and on the localHow are people handling authorization?I noticed that with V10, any mentions of `trpc-shield` are gone from the documentation. Also, it onlVitest context router callerHi, Im trying to setup vitest to test trpc. I would like to have a trpc approuter caller to be accesWebSocket connection hangs after significant amount of data passed through the connection.Hey! I've been really enjoying using tRPC on my latest project, but have gotten stuck getting websoCannot read properties of undefined (reading 'data') of res.error.data, when trpc errors outHello everyone, I am using `@trpc/react-query` alongside `trpc` for express, and I am experiencing aIs there an example of a real world non trivial app?Something that includes type inference, nested fields, calculated fields, nested React components th