I'm trying to map the results returned from a fake endpoint that contains an array of user objects with properties like id. But I can't figure out what to put into the map operator to make it work, for example, I want to add 10 to all the IDs. Here's my service's code:
getUsers(): Observable<IUsers[]> {
return this._http.get<IUsers[]>('https://jsonplaceholder.typicode.com/users')
.map((users: IUsers[]) => users.find(x => (x.id + 10)))
.do(data => console.log('All: ' + JSON.stringify(data)))
.catch(this.handleError);
}
inside .find()
, it returns 'number' not assignable to type 'boolean'
. How should I construct this the arrow function in my .map()
?
I think you want to replace your find
by a map
. Find
returns the value for which your evaluation is true
. (x.id + 10)
isn't. That is why you get that error.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.