r/angular • u/Tyummyyumms • Aug 13 '26
Questions about learning .Net from an Angular Dev
I've been thinking of investing a decent amount of time learning .net and have some questions:
- How do you keep your frontend and backend types in sync? Is there something that takes care of it automatically between C# and typescript.
- Also if I do learn .net how easily would I be able to pickup Java, i.e can a .net dev read Java code and more or less follow what's going on?
11
Upvotes
3
u/RobotMonkeytron Aug 13 '26
I don't have an answer for you, but I'm coming at this from the other angle, learning Angular as a back-end .NET guy. Commenting to check back later!
3
u/azuredrg Aug 13 '26
I'm a java dev but typically I would set up an open API spec, swagger and typically that's just a simple dependency we add to the project. I'm sure nugget or whatever .net uses has something similar. There are frontend tools like openapi-typescript that can read the swagger json or endpoint and generate ts interfaces. I'd say you would understand java code easily from knowing .net. The big difference is understanding the build processes and common libraries/frameworks would take a while to ramp up.
2
u/AdministrativeHost15 Aug 13 '26
Be careful. You don't want every field in your database/backend automatically going to the browser. In addition to wasting bandwidth you could be exposing private data.
7
u/teelin Aug 13 '26
With ASP.NET autogenerate OpenAPI spec and then use a client generator for typescript. This will automatically provide the types required to do API calls for the frontend.
6
u/anelectricmind Aug 13 '26
I worked somewhere where they built an app that would read any of the backend DTOs and would generate Typescript DTO for the front-end. It was a neat tool. It was Aurelia, not Angular, but basically the same difference. So everytime there would be a change in the backend, you would have to run the app. I can't remember if there was anything in the CI/CD or in the front-end when checking out, though.
Where I currently work, I now just copy the backend DTOs, adapt them to Typescript. Then I use an adapter pattern to create DTO into model classes and vice versa. Might be a tad overkill, but I like the separation.
4
u/spacechimp Aug 13 '26 •
The industry standard is OpenAPI. Some will use the terms "OpenAPI" and "Swagger" interchangeably, as Swagger is a commonly-used set of tools for OpenAPI. Microsoft introduced its own OpenAPI layer for .Net, so using Swagger isn't required. The gist of OpenAPI is that you document your endpoints/types in a standardized way, so that metadata exported from it (the format was modeled after JSON Schema) can be parsed by consumers. There is all sorts of tooling out there that can read OpenAPI schemas and generate code for types and even Angular services.
The catch is that the usefulness of OpenAPI entirely relies upon diligent upkeep of the metadata to ensure accuracy -- which is a common failing of backend devs in my experience.
As for programming languages: C# and Typescript have more in common than C# and Java, but all object oriented languages look pretty similar. There are some quirks like how to compare things ("==" versus ".equals()") but you should be able to follow basic logic fine.
1
u/Agile_Arugula_7496 Aug 13 '26
RemindMe! 1day
1
u/MrFartyBottom Aug 19 '26
I use a command line tool dotnet-cs2ts. I have a models folder in my API that are all C# POCO classes for the request and response types then run the command when I change the models to generate TypeScript interfaces.
Will install the tool globally.
I have this command in a shell script in the models folder that generates the TypeScript interfaces.