<p dir="auto">The error is reported in case when the indexer is a union type of string|number:</p>
<p dir="auto">var a:number|string<br>
var b:any<br>
var c = b[a]; &lt;- TS2342</p>
<p dir="auto">I have declared <code class="notranslate">function getter(key: string|number)</code>.<br>
Inside I try to do <code class="notranslate">var x = someObject[key]</code><br>
I get a TS error saying "An index expression argument must be of type 'string', 'number' or 'any'.<br>
Obviously <code class="notranslate">key</code> satisfies this constraint as it is either a string or a number. But I guess the TS compiler does hard type equality checks in this case.</p>