COMPARISON · VALIDATION

class-validator vs. yup

Side-by-side comparison · 9 metrics · 16 criteria

class-validator v0.15.1 · MIT
Weekly Downloads
4.5M
Stars
11.8K
Gzip Size
105.8 kB
License
MIT
Last Updated
3mo ago
Open Issues
312
Forks
844
Unpacked Size
5.3 MB
Dependencies
yup v1.7.1 · MIT
Weekly Downloads
5.7M
Stars
23.7K
Gzip Size
14.2 kB
License
MIT
Last Updated
8mo ago
Open Issues
241
Forks
939
Unpacked Size
270.4 kB
Dependencies
4
DOWNLOAD TRENDS

class-validator vs yup downloads — last 12 months

Download trends for class-validator and yup2 download series from Jun 2025 to May 2026. Use left and right arrow keys to inspect monthly values.011.9M23.8M35.8M47.7MJun 2025SepDecMarMay 2026
class-validator
yup
FEATURE COMPARISON

Criteria — class-validator vs yup

API Philosophy
class-validator
Imperative, decorator-driven, validation invoked on class instances.
yup
Declarative, fluent API, validation invoked on schema objects.
Learning Curve
class-validator
Steeper for those unfamiliar with TypeScript decorators; intuitive for TS experts.
yup
Generally lower, with a clear and consistent API fluent style.
Composition Style
class-validator
Primarily through class inheritance and mixins.
yup
Through fluent API chaining and nesting schema definitions.
Framework Synergy
class-validator
Excellent integration with decorator-heavy frameworks like NestJS.
yup
Broad compatibility across diverse JavaScript environments and frameworks.
Bundle Size Impact
class-validator
Larger footprint due to decorator dependency and feature set.
yup
Minimal impact, significantly smaller and optimized for size.
Extension Mechanism
class-validator
Relies on class inheritance and custom decorators.
yup
Built through method chaining and schema composition.
Primary Integration
class-validator
Tightly integrated with TypeScript class structures and OOP patterns.
yup
Standalone, flexible schema-building approach applicable in various JS contexts.
Data Flow Separation
class-validator
Validation logic is co-located with class definitions.
yup
Schemas are distinct entities separate from the data being validated.
Dependency Footprint
class-validator
May have more internal dependencies related to decorator processing.
yup
Generally has fewer direct runtime dependencies.
Error Reporting Detail
class-validator
Can provide detailed context tied to class constraints and metadata.
yup
Offers robust error objects with pathing and constraints.
Schema Definition Style
class-validator
Uses TypeScript decorators directly on class properties for validation rules.
yup
Defines validation schemas as separate, declarative JavaScript objects using a fluent API.
TypeScript Decorator Usage
class-validator
Core feature, enabling meta-programming for validation within class definitions.
yup
Not a primary dependency; offers optional type inference with TypeScript.
Validation Result Handling
class-validator
Errors often associated with specific class properties and validation contexts.
yup
Returns structured error objects or boolean outcomes from schema validation calls.
Scalability for Complex Models
class-validator
Scales well using OOP principles for intricate class hierarchies.
yup
Scales via schema composition and modular definition.
Code Readability for Validation
class-validator
Validation rules are directly visible within the data model class.
yup
Validation rules are defined in dedicated schema files or objects.
Developer Experience with TypeScript
class-validator
Highly idiomatic and productive for experienced TypeScript developers using classes.
yup
Provides good type safety and inference, accessible to a wider audience.
VERDICT

Class-validator excels as a decorator-based validation library, primarily leveraging TypeScript's meta-programming capabilities. Its core philosophy revolves around defining validation rules directly within class definitions using decorators, making it an intuitive choice for developers already deeply invested in a class-oriented, TypeScript-first development paradigm. This approach promotes co-location of business logic and validation, leading to highly readable and maintainable codebases, especially within larger applications.

Conversely, yup stands out for its "dead simple" object schema validation. Its philosophy centers on creating reusable, declarative schema objects that can be independently defined and then used to validate any data structure, particularly objects. This makes yup remarkably flexible, serving as an excellent standalone validation utility or a component within larger data-handling pipelines where schema definition is separate from data transformation or business logic.

A key architectural difference lies in their fundamental API design and data flow. Class-validator operates by instantiating classes and then invoking validation methods, often implicitly through the validator library's mechanisms. The validation state is typically associated with the class instance itself. In contrast, yup defines explicit schema objects. Validation is performed by calling methods on these schema objects, passing the data to be validated as an argument, resulting in a clear separation between schema definition and data.

Another technical distinction arises from their extension and composition models. Class-validator relies heavily on decorators and class inheritance to extend validation logic. This aligns well with object-oriented patterns, allowing for sophisticated validation hierarchies. Yup, on the other hand, employs a fluent API and a composition-based approach. Schemas are built by chaining methods, and complex schemas are composed by nesting or referencing simpler ones, offering a more functional and declarative style of schema construction.

The developer experience also contrasts significantly. Class-validator offers a seamless experience for TypeScript developers familiar with decorators, requiring minimal boilerplate to set up complex validation rules directly within their models. However, debugging decorator-related issues can sometimes be challenging. Yup provides a clear, chainable API that is generally easy to grasp, even for developers less familiar with advanced TypeScript features. Its validation results are typically more straightforward to inspect and debug.

Performance and bundle size considerations show a notable divergence. Yup boasts a significantly smaller bundle size at 14.2 kB (gzip) compared to class-validator's 105.8 kB (gzip). This makes yup a more attractive option for applications where minimizing JavaScript payload is critical, such as client-side applications or serverless functions with strict size limits. Class-validator's larger footprint is a consequence of its rich feature set and its reliance on decorators, which may introduce some overhead.

A practical recommendation hinges on your project's architecture and primary language. If your project heavily utilizes TypeScript classes and decorators for its domain modeling, class-validator offers a cohesive and integrated solution. It's ideal for validating incoming API payloads represented as TypeScript classes. For projects requiring flexible, standalone schema definition or validation across various JavaScript environments without heavy reliance on TypeScript decorators, yup is often the better choice.

Regarding ecosystem integration and maintenance, both packages are well-established within the Node.js and TypeScript communities. Class-validator's reliance on decorators means it's tightly coupled with TypeScript's compilation process. Yup, being a more standalone schema builder, can be more easily integrated into diverse build processes or JavaScript-only environments. Both have active communities, as indicated by their substantial download counts and GitHub engagement, suggesting good long-term maintenance prospects.

Considering niche use cases, class-validator's decorator-first approach makes it exceptionally well-suited for frameworks that automatically instantiate and manage classes, such as NestJS, where it can be used with minimal configuration. Yup's flexibility and smaller footprint make it a strong contender for front-end form validation libraries or as a general-purpose data validation utility in serverless environments where initial load time and bundle size are paramount.

CORRECTIONS

Spot wrong data here?

A short note helps us fix it.

Anonymous · No account · No email back

RELATED COMPARISONS 8
ajv vs class-validator ★ 26.5K · 157.6M/wk class-validator vs ow ★ 15.7K · 5.6M/wk class-validator vs valibot ★ 20.5K · 10.3M/wk class-validator vs joi ★ 33.0K · 14.6M/wk @sinclair/typebox vs class-validator ★ 11.8K · 52.3M/wk class-validator vs superstruct ★ 18.9K · 7.1M/wk class-validator vs zod ★ 54.7K · 99.1M/wk class-validator vs fast-xml-parser ★ 14.9K · 44.6M/wk