In my Angular app I have an issue with the response of an API call:
private async getActor(actor:string) {
const response = await this.searchActor.getActorImage(actor).toPromise()
let actPics = []
for (var val of (response as any[]).value) {
actPics.push(val.thumbnailUrl)}
}
My app runs fine but I have this message in the console when I run ng serve
Error: src/app/quiz-editor/actor-question/actor-question.component.ts:55:41 - error TS2551: Property 'value' does not exist on type 'any[]'. Did you mean 'values'?
55 for (var val of (response as any[]).value) { ~~~~~
node_modules/typescript/lib/lib.es2015.iterable.d.ts:75:5 75 values(): IterableIterator; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 'values' is declared here.
When I console.log(response)
I get:
I did some research and I read that I should declare response
but how should I do it?.
I've tried this solution:
private async getActor(actor:string) {
const response: { value:any[] } = await this.searchActor.getActorImage(actor).toPromise()
let actPics = []
for (let val of response.value) {
actPics.push(val.thumbnailUrl)}
}
But now I have this error:
Error: src/app/quiz-editor/actor-question/actor-question.component.ts:55:11 - error TS2696: The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead?
Property 'value' is missing in type 'Object' but required in type '{ value: any[]; }'.
55 const response: { value:any[] } = await this.searchActor.getActorImage(actor).toPromise()
~~~~~~~~
src/app/quiz-editor/actor-question/actor-question.component.ts:55:23
55 const response: { value:any[] } = await this.searchActor.getActorImage(actor).toPromise()
~~~~~
'value' is declared here.