title: Mapped type lookup doesn't require object type to be set correctly with function returned from another function
body: <p>I'm trying to implement a function that takes an event name and a properties object that can vary with the name of the event. The function that takes the event name and properties object is returned from another function, but typescript doesn't seem to be enforcing the type of the properties object correctly.</p>
  <p>I'm using typescript 3.7.2.</p>
  <p>I'm implementing the enum for the event name, the properties object types and the record for the properties like this:</p>
  <pre class="lang-js prettyprint-override"><code>export enum EventName {
    foo = 'foo',
    bar = 'bar',
    baz = 'baz',
  }
  
  interface IProperties {
  
  }
  
  interface IMoreProperties extends IProperties {
    prop1: string
  }
  
  export interface EventProperties extends Record&lt;EventName, IProperties&gt; {
    foo: IProperties;
    bar: IMoreProperties;
    baz: IProperties;
  }
  </code></pre>
  <p>When I use a function that doesn't return another function it correctly type checks that I've set the correct fields on the properties object:</p>
  <pre class="lang-js prettyprint-override"><code>function test&lt;E extends EventProperties, K extends keyof E&gt;(eventName: K, properties: E[K]): void {
  }
  
  test('foo', {});
  // Correctly requires that property be set.
  test('bar', {prop1: 'test'});
  </code></pre>
  <p>However when I return the function from another function it doesn't properly enforce that the properties object should have 'prop1' set:</p>
  <pre class="lang-js prettyprint-override"><code>function returnFunctionTest&lt;E extends EventProperties, K extends keyof E&gt;(
  ): (eventName: K, properties: E[K]) =&gt; void
  {
    function eventFunction(eventName: K, properties: E[K]): void { }
  
    return eventFunction;
  }
  
  const testFunc = returnFunctionTest&lt;EventProperties, keyof EventProperties&gt;();
  testFunc('foo', {});
  // Should error because it doesn't have 'prop1'
  testFunc('bar', {});
  </code></pre>
  <p>How do I force the returned function to type check correctly?</p>