title: Typescript "Element implicitly has an 'any' type because expression of type 'Rank' can't be used to index type 'IPowerCards'"
body: <p>I am building a card game and have the following types:</p>
  <pre><code>type Rank = &quot;A&quot;| &quot;2&quot;| &quot;3&quot;| &quot;4&quot;| &quot;5&quot;| &quot;6&quot;| &quot;7&quot;| &quot;8&quot;| &quot;9&quot;| &quot;T&quot;| &quot;J&quot;| &quot;Q&quot;| &quot;K&quot;;
  
  interface IPowerCards {
    [key: Rank]: any
  }
  </code></pre>
  <p>I also have the following object which I am trying to access with a rank string:</p>
  <pre><code>const powerCards: IPowerCards = {
    &quot;A&quot;: {
      canPlayOnAnyCard: true,
      canChangeSuit: true,
    },
    &quot;2&quot;: {
      canCounterPenaltyCard: true,
      penaltyAmount: 2,
    },
    ...,
  };
  </code></pre>
  <p>All the keys on this object are valid <code>Rank</code> types. I am trying to access values on the <code>powerCards</code> object using the following code:</p>
  <pre><code>const rank = getRank(card) as Rank;
  return rank &amp;&amp; powerCards[rank]?.canCounterPenaltyCard
  </code></pre>
  <p>However, I get the error <code>Element implicitly has an 'any' type because expression of type 'Rank' can't be used to index type 'IPowerCards'. Property 'A' does not exist on type 'IPowerCards'.</code>
  This error message doesn't make sense to me because I am ensuring that the <code>rank</code> variable, which is the variable I am using to access the <code>powerCards</code> object, is of <code>Rank</code> type, which is what I have specified in my <code>IPowerCards</code> type definition. Where am I going wrong? Thanks</p>