Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

i recommend the usage of zod instead of typebox #11

Closed
Victugord opened this issue Jan 9, 2023 · 4 comments
Closed

i recommend the usage of zod instead of typebox #11

Victugord opened this issue Jan 9, 2023 · 4 comments
Labels
enhancement New feature or request

Comments

@Victugord
Copy link

with Zod you can have the static type inference and a validator at the same time (https://zod.dev/)

@izakfilmalter
Copy link

@Victugord You can get the type similarly to Zod. I would prefer Zod since my whole code base uses it but, this works.

import { Static } from '@sinclair/typebox'
import { t } from 'elysia'

const Test = t.Undefined()
type Test = Static<typeof Test>

@SaltyAom
Copy link
Member

I have been experimenting with TypeBox and Zod back then in the beta day in fact I did ship Zod in some versions before migrating to TypeBox, because I have some problems back then that I don't remember anymore, mainly a performance difference between Zod and TypeBox (see benchmark).

As performance is a critical factor for the server side, and find that TypeBox is a good trade-off for that, I decided that Elysia will be using TypeBox as a primary method, and might support Zod later as I've been focusing on some other areas at the moment.

TypeBox does the validation and also has Static Type Inference which made Eden happens by using Static Type Inference.

You can get type inference using the following code:

import { Elysia, t, type UnwrapSchema } from 'elysia'

const UserSchema = t.Object({
	user: t.String()
})

type UserSchema = UnwrapSchema<typeof UserSchema>

Fun fact: I also prefer Zod over TypeBox on the client side.

@SaltyAom SaltyAom added the enhancement New feature or request label Jan 17, 2023
@SaltyAom
Copy link
Member

Close as we have no plan to migrate to Zod in the near future.

Will re-open once we planned to migrate.

@MuhammadAli-208
Copy link

any future plan to consider Zod as a type provider?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants