Having come from an Angular 1 background, my approach was to declare all models as POCOs and have web API calls return the data.
datacontext.query('api/OwnerData/GetOwners').then(function (d) {
vm.domain = d;
}
Transitioning to Angular2 and Typescript presents me with two options. Firstly, I can use map to get a JSON object and assign it to a component property for use in the view.
this.http.get(`/api/OwnerData/GetOwners`, { headers: this.getHeaders() })
.map(r => r.json())
.catch(handleError);
Alternatively, I could utilize a different mapping function to map to a strongly typed object. However, this would require defining the entire domain model in TypeScript on the backend, along with a suite of methods for mapping. This feels like a lot of unnecessary work and repetition. On the other hand, using JSON may sacrifice type safety.
What are your thoughts on this dilemma? Thank you for your time. (I am currently using Angular 2.4 and Typescript 2.1.5)