I like to convert a json string value to enum so it can show/render a custom string on the html page. error message: Type '{ id: number; name: string; status: string; }[]' is not assignable to type 'Status[]'
I have a json record like this:
{ id: 1, name: 'Some name', status: 'STATUS01' },
status.enum.ts
export enum Status {
'STATUS01' = 'Operational',
'STATUS02' = 'Some other status'
}
That enum is used in a model
import { Status } from './status.enum';
export class ServiceState {
id: number;
name: string;
status: Status;
}
In the service there is a function to retrieve al 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 return is throwing the error