I use the http client of Angular to retrieve data from an API. I define DTOs using typescript interfaces. One of the endpoints returns a json object which has dynamic keys which I would like to have mapped into a Map. I tried various things.
v1
export interface ItemDistribution {
id: number;
distribution: Map<string, number>; // I don't know the keys beforehand
}
v2
interface Distribution {
[key: string]: number;
}
export interface ItemDistribution {
id: number;
distribution: Distribution; // I don't know the keys beforehand
}
But, if I call the backend with http.get<ItemDistribution>(myUrl) the result gets parsed into a JavaScript object instead. I know that I could use Object.entries(...) on an object, but is it possible to get a Map directly?