title: Return Object (with specific key, value types) from function in TypeScript
body: <p>Suppose I have a function that needs to return something of type <code>StringMap&lt;string, boolean&gt;</code>. An example return that is valid is: <code>{"required": true}</code>.</p>
  
  <p>Now, I've read in a tutorial (it's not important which tutorial) you can create a function that has return type of <code>{ [s: string]: boolean }</code> and this is the same return type as the StringMap above.</p>
  
  <p>I don't understand how are these two the same return type? And how the second version is even valid?</p>
  
  <ol>
  <li>All the return types I have seen in TypeScript have only included the type in the past i.e. boolean, number, any. For example <code>function (): number {}</code>. In our second version we use <code>s: string</code> which means we give the variable a name, and specify it's type, how are we suddenly allowed to give the variable the name <code>s</code>?</li>
  <li>On top of that we put this string inside an array <code>[s: string]</code> as the key in the second version (therefore the key is now an array). While a StringMap has a string as the key.</li>
  </ol>