0

I am declaring a Map as follows:

 exampleMap:Map<string, string[]>;
 exampleMap['A']=['X,'XX'],

I am getting the following errror and dont know what it means nor how to fix it.

error TS7052: Element implicitly has an 'any' type because type 'Map<string, string[]>' has no index signature. Did you mean to call 'exampleMap.get'?

Any tips/suggestions on how to fix this?

Mary
  • 1,505
  • 5
  • 27
  • 44
  • Can you post the code that produces that error? The code in your question is incomplete and will not result in such an error. – CertainPerformance Mar 01 '22 at 23:18
  • I wrote some code that just passed without an error, from es3 until esnext in each versions. let exampleMap1: Map; exampleMap1 = new Map(); exampleMap1.set('A', ['X', 'XX']); const exampleMap2 = new Map(); exampleMap2.clear(); exampleMap2.set('B', ['Y', 'YY']); function a(exampleMap: Map) { exampleMap.clear(); } – Janos Vinceller Mar 02 '22 at 00:55
  • @JanosVinceller: thank you so much!! My mistake was I was setting the value as exampleMap['A']=['X,'XX'], instead of using exampleMap.set('A',['X,'XX']). Thank you!! – Mary Mar 02 '22 at 01:19
  • But then Mary, you forgot that part of your code, which would have been pretty important to the solution. Please edit your question. – Janos Vinceller Mar 03 '22 at 02:09

0 Answers0