Usage
Limitations
While Suvidha enhances Express.js with type safety and structure, it has some trade-offs:
1. TypeScript Required
- Designed for TypeScript. Pure JavaScript projects will not benefit from type inference or validation.
2. Zod Dependency
- Relies on Zod for validation. Alternative libraries such as Joi and Yup are not natively supported yet.
3. Global Middleware Compatibility
- Express global middleware (e.g.,
app.use(cors())
) won’t extend Suvidha’s typed context.
4. Shallow Immutability in Middleware
Suvidha enforces shallow readonly constraints on context objects. Although root-level keys are immutable, nested objects can still be modified:
5. Response Control
- Mixing
res.send()
with Suvidha’sHttp
classes can trigger dual-response warnings. - It is recommended to return data or throw errors rather than manually handling responses.
6. Custom Handlers Require Boilerplate
- To use
Http
classes orProtocol
objects in custom handlers, you need to implement theHandlers
interface.
7. Learning Curve
- Requires an understanding of Zod, type chaining, and Suvidha’s flow compared to raw Express.