I'm new to Typescript and I'd like to save the response of an HTTP GET to an array of a type defined by an interface.
getErrors() {
return this.http.get<ErrorsInterface[]>(environment.apiUrl+'errors').toPromise()
}
Then I declare the array like this and call the function getErrors()
errorsData: ErrorsInterface[]= []
this.errorsData = await this.ErrorsService.getErrors()
this.errorsData.forEach(res => {
console.log(res.number)
})
But I receive the following error:
ERROR Error: Uncaught (in promise): TypeError: this.errorsData.forEach is not a function TypeError: this.errorsData.forEach is not a function
I appreciate any help