title: How to force the type of a variable in typescript?
body: <p>I'm trying to write some function that converts a mongoose <code>User</code> model to a string with bullet points:</p>
  
  <pre><code>// Simplified version so you get the idea
  interface IUser {
    name: string
  }
  
  function userDetails (user: IUser, keys: string[]): string {
    return keys.map((k: string): string =&gt; {
      return `- ${k} : ${user[k]}`
    })
    .join('\n')
  }
  </code></pre>
  
  <p>But I'm having a strange compiler error, where <code>user[k]</code> is underlined:</p>
  
  <blockquote>
    <p>Index signature of object type implicitly has an 'any' type.</p>
  </blockquote>
  
  <p>Is there a way to "force" typescript to admin that <code>user[k]</code> is a string ? 
  I tried <code>user[k] as string</code> or <code>&lt;string&gt; user[k]</code> without success.</p>
  
  <p>Also, if I remove the <code>${user[k]}</code> from the returned string, then the compiler stop complaining</p>
  
  <p>Appart from the compiler error, everything works at runtime.</p>
  
  <p>Thanks !</p>