Giter VIP home page Giter VIP logo

Comments (4)

MuhammadAli-208 avatar MuhammadAli-208 commented on August 26, 2024 10

any future plan to consider Zod as a type provider?

from elysia.

SaltyAom avatar SaltyAom commented on August 26, 2024 4

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.

from elysia.

izakfilmalter avatar izakfilmalter commented on August 26, 2024

@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>

from elysia.

SaltyAom avatar SaltyAom commented on August 26, 2024

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

Will re-open once we planned to migrate.

from elysia.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.