Steve Kinney

Full-Stack TypeScript

Custom Data Transformers with tRPC

Custom Data Transformers

When you need to serialize Date, Map, or BigInt fields, consider SuperJSON. Install superjson and register it in both server and client:

import superjson from 'superjson';

const t = initTRPC.create({
	transformer: superjson,
});

And on the client:

createTRPCClient<AppRouter>({
	transformer: superjson,
	links: [
		/* ... */
	],
});

Now your date objects will remain actual Date objects on the client, not random strings.

Last modified on .