rd
rd2y ago

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;
5 Replies
Nick
Nick2y 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?
rd
rdOP2y ago
Yes I believe strict is enabled everywhere
Nick
Nick2y ago
Is that type a special class type or just a typescript type?
rd
rdOP2y 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
Nick
Nick2y ago
Ouch, that's not a good error though Usually means Typescript can't do typechecking on that type

Did you find this page helpful?