We’re looking at using
x typescript to generate the dtos for a large project to be used by a Next.JS app.
We found two issues with the generated code:
- several classes on our service models and DTOs that have the same name on different namespaces. These are mostly
helper classes or enums named “OrderBy” or
FilterBy, and compilation fails due to name colisions.
- Since it generates a single file, we end up with a single .ts file that is 1Mb in size with about 850 service models. We want to avoid having the client download and parse a single 1Mb file, specially since most of the time each page only needs 1/100 of that file.
To fix both issues, we looked at splitting manually the generated code into separate files.
For each service model we rendered a file with
IncludeTypes: <ServiceModel>. This only generates the model and the response. The DTOs are not picked up and the file fails to compile.
What would be the expected solution for us?
I think ideally we’d be able to pull all types and dependant types, and place each type on a separate file with folders based on the namespaces. This solution would solve both issues:
- the duplicated files issue because types with the same name would be on separate folders)
- the large file size, since we can leave webpack to bundle files;