End-to-end type safety
Elysia provides an end-to-end type safety between backend and frontend without code generation similar to tRPC, using Eden.
import { Elysia } from 'elysia'
import { treaty } from '@elysia/eden'
export const app = new Elysia()
.get('/', 'Hello Elysia!')
const client = treaty<typeof app>('localhost:3000')
const { data, error } = await client.get()
console.log(data) // Hello Elysia!
This works by inferring the types from the Elysia instance, and uses type hints to provide type safety for the client.
See Eden treaty.
Assignment
Let’s click the icon in the preview to see how’s the request is logged.