I have a function which returns promise:
Promise<
{
name: string;
guid: string;
country: string;
metadata: {name: string | null; value: string | null}[];
area: 'eastus' | 'westus';
lastAccessed: string | null;
control: {
city: string | null;
from: string;
greens: string[] | null;
primary: string;
secondaries?: {size: string; green: string[]} | undefined;
} | null;
}[]
>
and I would need to map it to the following interfaces:
export interface IGreenField {
name: string;
guid: string;
country: string;
area: string;
metadata: IMetaData[];
lastAccesses: string | null;
control: IControl | null;
}
export interface IMetaData{
name: string;
description: string;
}
export interface IControl {
city: string | null;
from: string[] | null;
greens: string | null;
primary: string | null;
secondaries: IControlSecondaries[] | null;
}
interface IControlSecondaries {
size: string | null;
green: string[] | null;
}
I have started map with:
return (await APIConsumer.getGreens()).map((green) => {
return {
guid: green.guid,
name: green.name,
area: green.area,
country: green.country,
metadata: green.metadata,
lastAccessed: green.lastAccessed,
control: green.control,
};
});
but I cannot figure out how to get it to match with the interfaces.