Hello guys Does anyone …

less than 1 minute read

Hello guys! Does anyone has practices with sharing API (NestJS) DTOs in shared library? DTOs have NestJS specific decorators for validation (Swagger, Class Validator etc.). It would be useful to share same DTOs in frontend and backend.

Responses:

Hey Class Validator works on the frontend. I also use it for validation.

Yes. But some other decorators are backend specific and don’t work in shared libs

You should use the DTO files as a base class. then extend from them

then you can share them easily

Still need to have multiple files, but that solution is good compromise. Thanks.

I do that, yes. I don’t use classes at all in my current design though, so not 100% the same :slightly_smiling_face:

But all of my interfaces for the data model are in a shared lib that both back-end and front-end depend on; works perfectly

Updated: