2

I'm stucked with this issue and I didn't find any solution even if there is a lot of question around this error, in my case I have a Map and I coudn't apply the solutions.

Here is my code :

I have to convert a map to send to the back-end like this :

const convMap = {} as Map<String, Array<DayConsumptionDto>>; map.forEach((val: Array<DayConsumptionDto>, key: string) => { convMap[key] = val; }); 

I'm getting this Error :

Element implicitly has an 'any' type because type 'Map<String, DayConsumptionDto[]>' has no index signature. Did you mean to call 'convMap.set'? 

if I put const convMap = {} as any it works perfectly but I don't do that, can you please help me to fix it ?

1
  • 1
    same as convMap, I have just to convert it to and array of key values to be sent to the back, so let map = new Map<string, DayConsumptionDto[]>(); Commented Apr 8, 2022 at 9:25

1 Answer 1

3

you can try like this

const convMap:{[key:string]:Array<DayConsumptionDto>}[] = [] map.forEach((val: Array<DayConsumptionDto>, key: string) => { convMap[key] = val; }); 

this will create an array

or

const convMap= {} as {[key:string]:Array<DayConsumptionDto>}; map.forEach((val: Array<DayConsumptionDto>, key: string) => { convMap[key] = val; }); 

this will create an object

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot dude ! Worked perfectly with the second one because I'm using an Object.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.