Nice post, even if I've been using typescript almost since it came out I always get bitten by these kinds of issues
What I tried to do to prevent these issues is to favor interfaces vs classes
whenever I know I'm dealing with an object or data manipulation I try to use interfaces but for functionality (views or viewmodels) I do try to favor classes.
Ditto. This whole issue could be prevented by favoring a data-oriented approach. In other words, donβt mix behavior (functions) and state (primitive properties).
So simply represent the data coming back as interface of json data and move faster. :)
π¨βπ« Co-Founder of This is Learning, Organizer of AarhusJS
βοΈ Writer, Speaker, FOSS Maintainer π Author
π Microsoft MVP π GitHub Star
π Nx Champion π¦Έ Angular Hero of Education
I agree. I would prefer to not create model classes that have methods for synchronizing with a server like the TypeScript TodoItem class in this example.
However, code like this is still seen in the wild, and I wanted a simple example. In fact, it's very common practice albeit not a good one to use ORMs on the server-side.
Your comments brings up some very valid points for discussion of code quality and software architecture.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Nice post, even if I've been using typescript almost since it came out I always get bitten by these kinds of issues
What I tried to do to prevent these issues is to favor interfaces vs classes
whenever I know I'm dealing with an object or data manipulation I try to use interfaces but for functionality (views or viewmodels) I do try to favor classes.
Ditto. This whole issue could be prevented by favoring a data-oriented approach. In other words, donβt mix behavior (functions) and state (primitive properties).
So simply represent the data coming back as interface of json data and move faster. :)
I agree. I would prefer to not create model classes that have methods for synchronizing with a server like the TypeScript TodoItem class in this example.
However, code like this is still seen in the wild, and I wanted a simple example. In fact, it's very common practice albeit not a good one to use ORMs on the server-side.
Your comments brings up some very valid points for discussion of code quality and software architecture.