colinhacks / zod

TypeScript-first schema validation with static type inference
https://zod.dev
MIT License
33.32k stars 1.15k forks source link

Comparison with typebox? #2482

Open kevinlul opened 1 year ago

kevinlul commented 1 year ago

The README has a great breakdown of how Zod compares with many similar libraries: https://github.com/colinhacks/zod#comparison. @sinclair/typebox could be added to the comparison; it seems to be comparable with similar syntax, and is widely used.

zgayjjf commented 1 year ago

+1 Seems like a good idea.

ghost commented 3 months ago

November, 2022 from the author of typebox on reddit:

TypeBox does however support the following additional functionality (if you need it)

  • Strict compliance with the JSON Schema specification.
  • Currently fastest JIT compiler / validator for JavaScript.
  • Closer alignment to the TypeScript Type System and Utility Types.
  • Supports Recursive Type Inference
  • Supports Conditional Type Mapping
  • Supports Custom Types with User Defined Inference Rules.
  • Value API for performing type operations on JavaScript values.
  • Extensive Test Suite for Ajv compliance
  • A more low level API to allow you to tune validation pipelines.

The benefit of using TypeBox mostly comes from being aligned to an industry standard specification (JSON Schema). From this you can leverage many frameworks that standardize on the specification (Fastify, OpenAPI, etc), utilize tools to auto generate documentation, generate user interface forms, or simply share types (and validation logic) across multiple systems (useful for micro services). TypeBox also uses the JSON Schema specification as it's Type Reflection Model.

In terms of performance, TypeBox currently ranks 3rd overall benchmarks here, with 1st and 2nd place given to AOT solutions (ones that require TS compiler transforms). TypeBox (like Ajv) provides a JIT compiler solution (for servers) as well as a dynamic type checking solution for applications under code evaluation constraints (for example browsers and certain cloud function providers)

Overall, I think most users of TypeBox just enjoy being closely aligned to JSON Schema specification while still being able to work with a Zod-like API.

Hope that helps

(Not sure what else might have changed since then.)