Skip to Content

tRPC

tRPCΒ  lets you call server procedures from the client with full type safety. By default, you wire up input and output validation with a schema library (zod, valibot, …). typia replaces that with createAssert β€” same one-line validator, generated from the TypeScript type directly.

import { initTRPC } from "@trpc/server"; import { v4 } from "uuid"; import typia from "typia"; import { IBbsArticle } from "../structures/IBbsArticle"; const server = initTRPC.create(); export const appRouter = server.router({ store: server.procedure .input(typia.createAssert<IBbsArticle.IStore>()) .output(typia.createAssert<IBbsArticle>()) .query(({ input }) => { return { id: v4(), writer: input.writer, title: input.title, body: input.body, created_at: new Date().toString(), }; }), }); export type AppRouter = typeof appRouter;

typia.createAssert<T>() returns (input: unknown) => T β€” exactly the shape tRPC’s .input() and .output() expect for a validator. On a mismatch the procedure rejects the call with a TypeGuardError carrying the path of the bad field.

If you want a Standard Schema-compliant validator (so the same definition also slots into other tools), use typia.createValidate instead.

Where to go next

Last updated on