title: How to ensure a TypeError if the value provided is not of the type implied by another property
body: <p>I am trying to write a generic type that will enforce the type of a given property (<code>value</code>) based on the value of another (<code>field</code>), where the value of <code>field</code> is a key in the type provided as the generic's parameter.</p>
  <p>Here is what I have tried:</p>
  <pre><code>type Rule&lt;M, F extends keyof M = keyof M&gt; = {
      field: F;
      value: M[F];
  };
  </code></pre>
  <p>Usage:</p>
  <pre><code>interface MyModel {
      firstName: string;
      lastName: string;
      age: number;
      isActive: boolean;
  }
  
  const rule1: Rule&lt;MyModel&gt; = {
      field: 'age',
      value: 'twentynine'
      // ^^  string | number | boolean
  };
  </code></pre>
  <p>Currently, the type of <code>rule1.value</code> is a union of all types in <code>MyModel</code>, no matter what the value of <code>rule1.field</code> is.</p>
  <p>Instead, I'm hoping for <code>rule1.value</code> to be of type <code>number</code> because the value &quot;age&quot; I have provided to <code>rule1.field</code> is a key in <code>MyModel</code> and the type is <code>number</code>.</p>
  <p>The following examples would have no errors:</p>
  <pre><code>const rule2: Rule&lt;MyModel&gt; = {
      field: 'age',
      value: 29
  };
  
  const rule3: Rule&lt;MyModel&gt; = {
      field: 'firstName',
      value: 'George'
  };
  </code></pre>