Hello everyone, I am currently working on mapping some API responses from The Muse API to an APIResponseInterface that I have created. Here's a snippet of my code:
Service that sends the request:
getJobs(page: number): Observable<APIResponseInterface>{
return this.http.get<APIResponseInterface>(this.url + page)
}
API Response Interface
export interface APIResponseInterface {
page?: number,
page_count?: number,
items_per_page?: number,
took?: number,
timed_out?: boolean,
total?: number,
results: Array<JobInterface>
}
Upon receiving the items in the "results", I want to map them to this interface:
export interface JobInterface {
contents: HTMLAllCollection,
name: string,
type?: string,
publication_date?: Date,
short_name?: string,
model_type?: string;
id? : number,
locations: LocationInterface[]
level: LevelsInterface[],
company: CompanyInterface,
}
In my Angular component, I'm using the following function to map the results into an array of JobInterface:
this.jobsService.getJobs(1)
.subscribe((response) => {
this.jobs = response.results.map<JobInterface>(job => {{
name: job.name
}}
)
console.log(this.jobs)
})
However, I am encountering errors such as:
TS2345: Argument of type '(job: JobInterface) => void' is not assignable to parameter of type '(value: JobInterface, index: number, array: JobInterface[]) => JobInterface'.
Can you please assist me in figuring out what mistake I might be making and the correct approach to resolve it?