Issue
I have a use case in which I am creating a metric using Math Expression-
new MathExpression({
expression: `SUM([${Object.keys(metricArguments).join(", ")}])`,
usingMetrics: metricArguments,
})
Here metricArguments is a Map<string,IMetric>
but usingMetrics
need Record<string,IMetric>
type.I wanted to ask how can I convert a Map<string,Imetric>
into Record<string,Imetric>
as I have my metrics stored in map.
I could also have inserted the metric in a Record type instead of map but could not find any method to do it.
Solution
You will need a function to convert the Map
into an object literal.
function convertMapToObject(metricArguments: Map<string,IMetric>): Record<string,IMetric> {
let newObject: Record<string,IMetric> = {}
for (let [key, value] of metricArguments) {
newObject[key] = value;
}
return newObject;
}
new MathExpression({
expression: `SUM([${Object.keys(metricArguments).join(", ")}])`,
usingMetrics: convertMapToObject(metricArguments),
})
Answered By - Hassan Naqvi
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.