Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Element implicitly has an 'any' type because type 'Map<String, DayConsumptionDto[]>' has no index signature

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 :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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 ?

>Solution :

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading