title: TypeScript error when dynamically setting color for `chalk` package
body: <p>The <a href="https://www.npmjs.com/package/chalk" rel="nofollow noreferrer">chalk package</a> is very popular for terminal styles in Node.</p>
  
  <p>I'm using TypeScript. I'm trying to set the color dynamically. But I am getting a TS error on compile.</p>
  
  <p>Code:</p>
  
  <pre class="lang-js prettyprint-override"><code>import chalk, { Chalk } from 'chalk';
  
  function getColor(): keyof Chalk {
    let color: keyof Chalk = 'green';
  
    color = 'yellow';
  
    return color;
  }
  
  const chalkColor = getColor();
  
  // Error on `chalk[chalkColor]`
  console.log(chalk[chalkColor]('message'));
  </code></pre>
  
  <p>Error (on <code>chalk[chalkColor]</code>):</p>
  
  <pre><code>This expression is not callable.
    Not all constituents of type 'boolean | (Chalk &amp; { supportsColor: ColorSupport; }) | (ChalkConstructor &amp; Function) | Level | ((r: number, g: number, b: number) =&gt; Chalk &amp; { supportsColor: ColorSupport; }) | ... 10 more ... | ((color: string) =&gt; Chalk &amp; { ...; })' are callable.
      Type 'false' has no call signatures.
  </code></pre>
  
  <p>How can I resolve this error?</p>