title: Typescript: How to derive one type from another using a map within the same interface
body: <p>I have the following type definitions</p>
  <pre><code>const enum INV_SEARCH_OPERATOR {
      EQUAL = &quot;EQUAL&quot;,
      LIKE = &quot;LIKE&quot;,
      CONTAINS = &quot;CONTAINS&quot;,
      CONTAINS_LIKE = &quot;CONTAINS_LIKE&quot;,
      NULL = &quot;NULL&quot;,
      NOT_NULL = &quot;NOT_NULL&quot;,
  }
  type SearchFieldTypeMap = {
      [INV_SEARCH_OPERATOR.EQUAL]: string;
      [INV_SEARCH_OPERATOR.LIKE]: string;
      [INV_SEARCH_OPERATOR.NULL]: [];
      [INV_SEARCH_OPERATOR.NOT_NULL]: [];
      [INV_SEARCH_OPERATOR.CONTAINS]: Array&lt;string&gt;;
      [INV_SEARCH_OPERATOR.CONTAINS_LIKE]: Array&lt;string&gt;;
  };
  type SearchCondition&lt;O extends INV_SEARCH_OPERATOR&gt; = {
      fieldName: SEARCH_FIELD
      operator: O
      values: SearchFieldTypeMap[O]
    }
  type SearchFieldCondition = {
      field: SearchCondition&lt;keyof SearchFieldTypeMap&gt;;
  };
  </code></pre>
  <p>Idea being that the value of the search condition is enforced based on the type of operator that is provided.
  However when I use this, it allows any of the <code>SearchFieldTypeMap</code> types to be used for any of the operator types. It doesn't seem to map through.</p>
  <p>e.g</p>
  <pre><code>const mySearchQuery: SearchFieldCondition = {
    field: {
      fieldName: &quot;FilterX&quot;,
      operator: INV_SEARCH_OPERATOR.NULL,
      values: ['Hello']
    }
  };
  </code></pre>
  <p>I would have expected to throw an error since the expected value type for <code>INV_SEARCH_OPERATOR.NULL</code> should be be an empty tuple <code>[]</code>.
  However it looks like <a href="https://i.stack.imgur.com/oGHV3.png" rel="nofollow noreferrer">this</a></p>
  <p>What am I doing wrong?</p>