<p dir="auto"><strong>TypeScript Version:</strong></p>
<p dir="auto">1.8.7 (ES6 mode)</p>
<p dir="auto"><strong>Code</strong></p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="type SymbolKeysGiveNumbers = { [x: symbol]: number };"><pre class="notranslate"><span class="pl-k">type</span> <span class="pl-smi">SymbolKeysGiveNumbers</span> <span class="pl-c1">=</span> <span class="pl-kos">{</span> <span class="pl-kos">[</span><span class="pl-s1">x</span>: <span class="pl-smi">symbol</span><span class="pl-kos">]</span>: <span class="pl-smi">number</span> <span class="pl-kos">}</span><span class="pl-kos">;</span></pre></div>
<p dir="auto"><strong>Expected behavior:</strong><br>
Should work</p>
<p dir="auto"><strong>Actual behavior:</strong><br>
<code class="notranslate">Error: an index signature parameter must be 'string' or 'number'</code></p>
<p dir="auto">However:<br>
<strong>Code</strong></p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="let x: { [key: string]: any };
x[Symbol(&quot;abcd&quot;)] = 12;"><pre class="notranslate"><span class="pl-k">let</span> <span class="pl-s1">x</span>: <span class="pl-kos">{</span> <span class="pl-kos">[</span><span class="pl-s1">key</span>: <span class="pl-smi">string</span><span class="pl-kos">]</span>: <span class="pl-smi">any</span> <span class="pl-kos">}</span><span class="pl-kos">;</span>
<span class="pl-s1">x</span><span class="pl-kos">[</span><span class="pl-smi">Symbol</span><span class="pl-kos">(</span><span class="pl-s">"abcd"</span><span class="pl-kos">)</span><span class="pl-kos">]</span> <span class="pl-c1">=</span> <span class="pl-c1">12</span><span class="pl-kos">;</span></pre></div>
<p dir="auto"><strong>Expected behavior:</strong><br>
Should not work based on the error above</p>
<p dir="auto"><strong>Actual behavior:</strong><br>
Works</p>
<p dir="auto"><strong>Conclusion</strong><br>
<code class="notranslate">Symbol</code> type should be allowed as an index signature parameter type as in practice it is accepted as a valid index key type. Even the error message when doing something like:</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="let x: { [key: string]: any };
x[true] = 1;"><pre class="notranslate"><span class="pl-k">let</span> <span class="pl-s1">x</span>: <span class="pl-kos">{</span> <span class="pl-kos">[</span><span class="pl-s1">key</span>: <span class="pl-smi">string</span><span class="pl-kos">]</span>: <span class="pl-smi">any</span> <span class="pl-kos">}</span><span class="pl-kos">;</span>
<span class="pl-s1">x</span><span class="pl-kos">[</span><span class="pl-c1">true</span><span class="pl-kos">]</span> <span class="pl-c1">=</span> <span class="pl-c1">1</span><span class="pl-kos">;</span></pre></div>
<p dir="auto">includes 'symbol' as a valid option:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="An index expression argument must be of type 'string', 'number', 'symbol' or 'any'"><pre class="notranslate"><code class="notranslate">An index expression argument must be of type 'string', 'number', 'symbol' or 'any'
</code></pre></div>
<p dir="auto">TypeScript now has a ES6 target mode which includes definitions <code class="notranslate">Symbol</code>. However when trying to index an object with a symbol, I get an error (An index expression argument must be of type 'string', 'number', or 'any').</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="var theAnswer = Symbol('secret');
var obj = {};
obj[theAnswer] = 42; // Currently error, but should be allowed"><pre class="notranslate"><span class="pl-k">var</span> <span class="pl-s1">theAnswer</span> <span class="pl-c1">=</span> <span class="pl-v">Symbol</span><span class="pl-kos">(</span><span class="pl-s">'secret'</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-k">var</span> <span class="pl-s1">obj</span> <span class="pl-c1">=</span> <span class="pl-kos">{</span><span class="pl-kos">}</span><span class="pl-kos">;</span>
<span class="pl-s1">obj</span><span class="pl-kos">[</span><span class="pl-s1">theAnswer</span><span class="pl-kos">]</span> <span class="pl-c1">=</span> <span class="pl-c1">42</span><span class="pl-kos">;</span> <span class="pl-c">// Currently error, but should be allowed</span></pre></div>