I am working with a class that contains information about different programs. My goal is to filter out the active and inactive programs, and then retrieve the names of those programs as an array of strings.
Below is the structure of the Program class:
export class Program {
ID: number;
ProgramDescription: string;
ProgramName: string;
ProgramStatus: string;
FiscalYear: string;
SupervisorID: string;
DBN: string;
IsActive: string;
}
Here are some methods I have implemented in the service:
getPrograms(): Observable<Program[]> {
return this.httpClient.get<Program[]>(environment.apiBaseURL + 'api/Program')
.pipe(
map(data => data)
);
}
getActivePrograms(): Observable<Program[]> {
return this.getPrograms()
.pipe(
map(data => data.filter(program => program.IsActive === 'Y'))
);
}
getActiveProgramNames(): Observable<string[]> {
return this.getActivePrograms()
.pipe(
map(data => data.map(program => program.ProgramName.toString()))
);
}
However, when trying to retrieve the active program names in getActiveProgramNames(), I encounter the following error:
Type Program[] is not assignable to type string[]