I am facing an issue where I need to convert a JSON string value into an enum to display a custom string on an HTML page. The error message states: Type '{ id: number; name: string; status: string; }[]' is not assignable to type 'Status[]'
Here is an example of the JSON record:
{ id: 1, name: 'Some name', status: 'STATUS01' },
In the file status.enum.ts, we have the following enum defined:
export enum Status {
'STATUS01' = 'Operational',
'STATUS02' = 'Some other status'
}
This enum is used in a model as shown below:
import { Status } from './status.enum';
export class ServiceState {
id: number;
name: string;
status: Status;
}
Within the service, there is a function to retrieve all statuses (dummy data):
getStatuses(): Observable<ServiceState[]> {
const response = [
{ id: 1, name: 'One', status: 'STATUS01' },
{ id: 2, name: 'Two', status: 'STATUS01' },
{ id: 3, name: 'OneTwo', status: 'STATUS02' },}
];
return of(response);
}
The current issue arises when trying to handle the return values.