Type interface of map error
Why does this not work? I have been googling for over 40 minutes but I don't get it. I know I could do something like
new Map<string, number>()
but why not by using the interface? Thanks!3 Replies
what you want is
let tableData = new Map<string, number>();
new Map<string, number>()
and new Map<TableData>()
are fundamentally different things.
The first generic argument (string
and TableData
) is for the map's key, and the second number
is for the map's values.
You can't just merge the two generics together into an interface, you have to provide them separately - putting TableData
first is telling TS that they key type is TableData
, but you're not providing a value type, hence the complaint about 0 or 2 arguments.if you really want to have an interface you can split it like this
let tableData = new Map<keyof TableData, TableData[string]>();