Quick task description:
I have an object of areas and I need to do some processing of those areas
depending on their type using the areaProcessor function. Also, only 'toCreate' and 'toRemove' types of areas should be processed.
type AreaType = 'toCreate' | 'toRemove' | 'toUpdate';
const areas: AreaType = { toCreate: [], toUpdate: [], toRemove: [] };
const areaProcessor = (areaType: AreaType, gf: any): any => {};
Object.entries(areas)
.filter(([areaType, _]) => areaType === 'toCreate' || areaType === 'toRemove')
.flatMap(([areaType, gf]) => areaProcessor(areaType, gf));
Problem:
The problem here is that typescript throws a type error for areaProcessor:
Argument of type 'string' is not assignable to parameter of type '"toCreate" | "toRemove"'.
Obviously, it's because in the flatMap function areaType is of type string, but I'd like it to be of type
type AreaType = 'toCreate' | 'toRemove' | 'toUpdate';
Question:
How do I do the conversion then?
P.S.
I used any just to avoid introducing new, irrelevant types.
areas?