This particular piece of code is causing an error:
function myFilter(debts:Map<string, number>) : Map<string, number>{
return new Map([...debts]
.map(d => [d[0], Math.round(d[1] * 10) / 10]) // error
.filter(d => d[1] != 0)
)
}
The error occurs because the map()
function can potentially yield [string | number][][]
.
To resolve this issue, the following corrected code works without errors:
function myFilter(debts:Map<string, number>) : Map<string, number>{
return new Map([...debts]
.map(d => [d[0], Math.round(d[1] * 10) / 10] as [string, number])
.filter(d => d[1] != 0)
)
}
The necessity of this assertion in the code remains unclear to me.