Within a predefined interface, I have the following properties:
export interface User {
userID : number;
userName : string;
userAge : string;
}
In addition, there is a service that retrieves dummy data from a mock REST API.
getUsers(){
return this.http.get("https://fakerestapi.azurewebsites.net/api/Authors").toPromise();
}
Within my component, I consume this service and transform the data into a list of users using the code below:
_service.getUsers().then(i => { this.userList = i as User[]; console.log(this.userList) });
It's worth noting that I utilize 'AS' to convert the response into my specific user[] array.
CONCERN:
The dummy REST API returns the following data:
{
"ID": 1,
"IDBook": 1,
"FirstName": "First Name 1",
"LastName": "Last Name 1"
}
The User class does not include properties like ID or IDBook. Surprisingly, when checking the console, it automatically adjusts the definition of the User class and displays all the data even if the properties do not match.
Link:https://stackblitz.com/edit/angular-pryy3f?file=src%2Fapp%2Fappservice.service.ts
In my opinion, only matching properties should be displayed, not all of them.