I am receiving some json object from a file, and I want to parse some of the fields to predefined values.
import jobsRaw from '../../data/jobs.json';
I created a type that describes my object, but I want the status to have only my predefined values, if else I might define a fallback value.
export type Job = {
type: string;
id: string;
status: JobStatus;
warehouseId: string;
relatedCell: string;
relatedDocument: string;
partnerName: string;
potatoType: string;
relatedBoxes: string[];
boxCount?: number;
createdAt: string;
completedAt: string;
};
This is the mapping I'm trying with:
const jobs: Job[] = jobsRaw.map((job: Job) => ({
...job,
status: JobStatus[job.status],
boxCount: job.relatedBoxes.length,
}));
I want to create some sort of JobStatus type that I can parse my received string value with.