I've encountered an issue with TypeScript syntax, specifically when a WebAPI returns a DTO containing two objects. The object being returned looks like this:
{
"userList": [{
"id": 1,
"firstNm": "John",
"lastNm": "Doe"
},
{
"id": 2,
"firstNm": "Jim",
"lastNm": "Doe"
}
],
"selectedIds": [158, 155]
}
Within my Angular TS code, I attempted to declare users
as any[]
, however the CLI compiler is highlighting the userList property in red and stating that 'userList' is not a member of the type of any[]
.
I also tried creating an interface for User with memberList: any[]
, but encountered the same error message. So when defining users: any[]
and User[]
, I'm faced with the same issue.
Any assistance on this matter would be greatly appreciated.
Thank you,
getUsers() {
this.meetingService.GetCommitteeMembersAsync(this.request.meetingId)
.subscribe((data: any[]) => {
var _test = data;
this.users = _test.userList;
});
}