type mismatch between tRPC return (in sveltekit) and defined type
i've got this piece of code:
the issue is that the type of res, as returned from trpc, is
SerializeObject<UndefinedToOptional<Card & { tasks: Task[]; }>>[]
, while i've type my cards state as (Card & { tasks: Task[]; })[];
. as far as i can tell, there should be no mismatch in type here, but the linter isn't happy with trying to pass res
as the same type as cards
6 Replies
Do you have a transformer set up? What’s the exact and complete error?
not entirely sure if i have a transformer, i mostly tried to follow the instructions here: https://icflorescu.github.io/trpc-sveltekit/, but then i added my prisma client onto the context.
error is:
now that i look at it closer, im assuming that the Date type when returned from trpc is string, but still Date on the actual type imported from the prisma client ?
ok, added superjson; seems like it'll make things a fair bit easier
Yep dates can't survive json without superjson
The error message is useful once you understand this
yea, thanks! quick question: I just followed the docs surrounding how to add superjson, but the sveltekit trpc setup is a bit different that that in the regular docs. not sure if this is enough context, but do I need to add the transformer on both client initializations here?
seems like it has something to do with server vs client, but im not entirely clear on whats happening here
i added to both just to be safe
I'm guessing the starter you're using does SSR and client rehydration. I believe this pattern is common on NextJS to support both environments
Not my area of experience though
gotcha, thanks for the help