79712449

Date: 2025-07-23 19:11:56
Score: 0.5
Natty:
Report link

You're asking a few different things here. First, you already partly answered your question on ESM compatibility, and partly the const-style enums etc. The remaining question is how to share this between angular and nest.

Nothing in a DTO should be Angular or Nest specific. How you set it up is kinda up to you, and out of scope of at least the titular question. So I'll take the second part to try to answer.

---

What you want to do here is essentially share an typescript package, between two different typescript projects. How, depends on how your projects are set up. I can only suggest vague ideas and concepts, you'll have to either clarify the question further, or figure out the rest of the way on your own.

Do you have a monorepo set up? Something like nx.dev or turborepo? npm workspaces? They each have their own ways of setting up and sharing projects.

Otherwise, if you have separate repos, you could again do a few things differently. For one - you could install the DTO in, say, your NestJS package. You would have to export that library as an actual export. You could then add that entire package as a dependency for your Angular project. That would, of course, suck for various reasons.

The last option I'll propose is to make a third package, call it "validations" or something similar, and share that as a dependency for both other packages.

That's how you can get clean isolation, no duplication, even versioning support, support tree shaking properly (so that you actually import typescript files into your sources, before you transpile the resulting app code into javascript.

Reasons:
  • RegEx Blacklisted phrase (2.5): Do you have a
  • Long answer (-1):
  • No code block (0.5):
  • Contains question mark (0.5):
  • High reputation (-2):
Posted by: Zlatko