T

tRPC

โ“-help

Join Server

JSON inferred router output not matching

Bbongjovi2/23/2023
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;
Nnlucas2/23/2023
Have you enabled strict mode in your tsconfig? You should use it everywhere in this ecosystem
Nnlucas2/23/2023
But JsonValue does declare null as a possible value there, are you sure thatโ€™s not it?
Bbongjovi2/23/2023
Yes I believe strict is enabled everywhere
Nnlucas2/23/2023
Is that type a special class type or just a typescript type?
Bbongjovi2/23/2023
Hmm, I just reset my TS server and I think it's updated, my apologies.
Bbongjovi2/23/2023
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.
Bbongjovi2/23/2023
So likely Prisma related and tRPC is doing everything correctly ๐Ÿ‘
Bbongjovi2/23/2023
Thanks for your help and sorry for not trying that sooner
Nnlucas2/23/2023
Ouch, that's not a good error though
Nnlucas2/23/2023
Usually means Typescript can't do typechecking on that type