zijianhuang / webapiclientgen

Strongly Typed Client API Generators generate strongly typed client APIs in C# .NET and in TypeScript for jQuery and Angular 2+ from ASP.NET Web API and .NET Core Web API
MIT License
168 stars 38 forks source link

Split generated class to multiple files (TypeScript). #96

Closed AKlaus closed 4 years ago

AKlaus commented 4 years ago

Is there a way to split generated classes into multiple files? Ideally to have one class per file. I'm interested in TypeScript files in particular.

Have another question. Generated TypeScript POCOs are interfaces. Is there a way to generate them as classes with customised serialisation/deserialisation, so complex objects get converted to/from string nicely?

zijianhuang commented 4 years ago

Interface vs Class

I have being doing heavy TypeScript programming with jQuery and Angular 2+ since 2012 in complex business fat clients and had yet found a situation in which I need to use DTO class. You probably had known that interface won't yield a footprint in the JavaScript output, but class yield footprint in the JS.

If you google around, you may find many good posts discussing interface vs class in TypeScript for DTO. Or you may present your case (customised serialisation/deserialisation? with examples) of using DTO class in this post or the other forum to see if there could be some legitimate case that DTO class is a must.

All in one vs multiple files

While both approaches could have their own pros and cons depending on the contexts. However, I would list 2 factors here.

  1. All in one won't make the JS output bigger, since tree shaking during build is fairly good. And using namespace rather than module is a preferred way of containing classes, Application developers need least knowledge of the file structure during programming.
  2. When updating the client API after updating the service, it is easy to diff.

Remarks: React is apparently not in favor of namespace, however, their development team seemed to be changing their mind as of one year ago. I might later revisit React. Or, if you are familiar with React, you may try to write a plug-in for React.

zijianhuang commented 4 years ago

no feedback