Reputation: 342
I'm building an angular 6 project with typescript 3.1.2. I'm calling a restful API that returns a JSON data set with a label name data. I'm getting the below error but the website works perfectly without any console error. Is this a bug or I'm I doing something wrong?
error TS2339: Property 'data' does not exist on type 'AgentData[]'.
Here is my Agent Component subscribing to the service.
This is the error from VS Code Editor:
[ts] Property 'data' does not exist on type 'AgentData[]'
Upvotes: 2
Views: 129
Reputation: 5311
your are looking for resp.data where resp is an array. you should be looking for resp[0].data
Upvotes: 0
Reputation: 3526
your method return type should be Observable<AgentData>
instead of Observable<AgentData[]>
Upvotes: 1