So I have the following problem, I need to pass the data Object into this method but the problem is that it says it doesn't have the hits property, usually I would just do (data:any) but since I also need the news data I can't, any way to solve this?
public getDataByPage(contentType: string, pageNum: number): void {
this.http.get(`https://hn.algolia.com/api/v1/search_by_date?query=${contentType}&page=${pageNum}&hitsPerPage=16`).pipe(
take(1),
withLatestFrom(this.news$),
tap(([data, news]) =>{
this.parseNewsData([...news, ...data.hits]);
})
).subscribe();
};
CodePudding user response:
Does this solve you problem?
this.parseNewsData([...news, ...(data as any).hits]);
a better solution would be:
this.http.get<any>('https://hn.algolia.com.....
or
this.http.get<{hits:number}>('https://hn.algolia.com.....
so data
will have the correct type