Recently, we started a new project with Angular and NestJS inside a monorepo Nx, and it works great. However, when we want to use @nestjs/swagger features inside a shared lib called "DTO", things start to break.
Firstly, Angular didn't compile anymore. Hopefully, I found a good Stackoverflow post covering this subject and followed the recommandation: create a webpack config to shim out the @nestjs/swagger package with Angular builder (Source: Post Stackoverflow)
Here is the custom webpack config:
import path from 'path';
export default function customConfig(config: any) {
return {
...config,
resolve: {
...config.resolve,
alias: {
...config.resolve.alias,
// shims out nestjs swagger module in the frontend for DTO sharing
'@nestjs/swagger': path.resolve(
__dirname,
'../../node_modules/@nestjs/swagger/dist/extra/swagger-shim'
),
},
},
};
}
And now, it compiles ! 🥳
But, some days later, I have another small problem: I'm unable to use PartialType, OmitType,... all the mapped-types described here: Mapped Types NestJS/Swagger
The error when the DTO is loaded:
TypeError: Class extends value () =\> {} is not a constructor or null
And it points to this DTO:
export class UpdateSpireDto extends PartialType(CreateSpireDto) {}
Once I remove the extends PartialType method, it works correctly.
Does anyone have an idea how to resolve this ?
Or any recommandation of how to share DTO/models/... Between frontent (Angular) and backend (NestJS) inside Nx ?
I already considered to remove the PartialType method and use only the class with the properties, but it is not a good idea in a long term project. Using these mapped-types would be a great advantage for us.
I've already looked to these posts:
How to use NX DTO libraries decorated with NestJS swagger api in frontend frameworks
How to enable Swagger for API interfaces shared between NestJS and Angular within Nx monorepo?
But my problem does not come from the nestjs decorators, only the methods mapped-types...
Thank you in advance and have a nice day !