@@ -108,8 +108,11 @@ const nuxtTrpcRootConfig = `/**
108108 */
109109import { initTRPC } from '@trpc/server'
110110import { Context } from '~/server/trpc/context'
111+ import superjson from 'superjson';
111112
112- const t = initTRPC.context<Context>().create()
113+ const t = initTRPC.context<Context>().create({
114+ transformer: superjson,
115+ })
113116
114117/**
115118 * Unprotected procedure
@@ -132,6 +135,7 @@ export const appRouter = router({
132135 .query(({ input }) => {
133136 return {
134137 greeting: \`hello \${input?.text ?? "world"}\`,
138+ time: new Date()
135139 }
136140 }),
137141})
@@ -176,13 +180,15 @@ export default createNuxtApiHandler({
176180
177181const nuxtTrpcPlugin = `import { createTRPCNuxtClient, httpBatchLink } from "trpc-nuxt/client"
178182import type { AppRouter } from "~/server/trpc/routers"
183+ import superjson from 'superjson';
179184
180185export default defineNuxtPlugin(() => {
181186 /**
182187 * createTRPCNuxtClient adds a \`useQuery\` composable
183188 * built on top of \`useAsyncData\`.
184189 */
185190 const client = createTRPCNuxtClient<AppRouter>({
191+ transformer: superjson,
186192 links: [
187193 httpBatchLink({
188194 url: "/api/trpc",
@@ -206,7 +212,8 @@ const hello = await $client.hello.useQuery({ text: 'client' })
206212
207213<template>
208214 <div>
209- <p>tRPC Data: {{ hello.data.value?.greeting }}</p>
215+ <!-- As \`superjson\` is already pre-configured, we can use \`time\` as a \`Date\` object without further deserialization 🎉 -->
216+ <p>tRPC Data: {{ hello.data.value?.greeting }} send at {{ hello.data.value?.time.toLocaleDateString() }}</p>
210217 </div>
211218</template>
212219`
@@ -309,6 +316,10 @@ export const moduleConfigs: Record<Modules, ModuleConfig> = {
309316 name : "zod" ,
310317 version : "^3.20.2" ,
311318 isDev : false
319+ } , {
320+ name : "superjson" ,
321+ version : "^1.12.1" ,
322+ isDev : false
312323 } ] ,
313324 nuxtConfig : {
314325 build : {
0 commit comments