title: Typed Generic Key Value Interface in Typescript
body: <p>I have the following example Object:</p>
  
  <pre><code>let foo: Foo = {
    'key1': { default: 'foo', fn: (val:string) =&gt; val },
    'key2': { default: 42, fn: (val:number) =&gt; val },
  
    // this should throw an error, because type of default and fn don't match
    'key3': { default: true, fn: (val:string) =&gt; val }
  }
  </code></pre>
  
  <p>The Interface should look something like this:</p>
  
  <pre><code>interface Foo {
    [key: string]: { default: T, fn: (val:T) =&gt; any }
  }
  </code></pre>
  
  <p>This of course doesn't work, because there's no <code>T</code> defined.</p>
  
  <p>So I thought about doing this:</p>
  
  <pre><code>interface FooValue&lt;T&gt; {
    default: T;
    fn: (val:T) =&gt; any;
  }
  
  interface Foo {
    [key: string]: FooValue&lt;?&gt;
  }
  </code></pre>
  
  <p>But there I got stuck, too. Because I can't define the generic type of <code>FooValue</code>.</p>
  
  <p>If I use <code>FooValue&lt;any&gt;</code> then of course everything is typed as <code>any</code>. Though that doesn't work.</p>
  
  <p>I want to ensure that the type of <code>default</code> and the parameter type of <code>fn</code> are always the same.</p>
  
  <p>Is there any solution? Or can't this be done?</p>