title: Arguments type constaint in Typescript function
body: <p>I'm struggling on this for a long time,</p>
  <pre class="lang-js prettyprint-override"><code>function processEntity&lt;
    T extends Record&lt;string, unknown&gt;,
    U extends keyof T = keyof T,
    V extends Pick&lt;T, U&gt; = Pick&lt;T, U&gt;
  &gt;(arg: {keys: Array&lt;U&gt;; resolver: (doc: V) =&gt; void}) {
    arg.resolver(...)
  }
  
  type Cat = {
    name: string
    age: number
  }
  
  processEntity&lt;Cat&gt;({
    keys: ['name'],
    resolver: (doc) =&gt; {
      // doc.name should exists
      // doc.age should be undefined
    },
  })
  </code></pre>
  <p>As you can see above, there is a function <code>processEntity</code> which accepts an object as the argument.</p>
  <p>What I want is to make <code>type of argument of arg.resolver</code> depends on type of <code>arg.keys</code>. Say if I pass <code>['name']</code> to <code>keys:</code> field, then when <code>doc.age</code> should not be accessable because <code>'age'</code> was missed in <code>keys</code> field.</p>
  <p>I've looked at some questions listed below but they does not help, so please help :pray:</p>
  <ul>
  <li><a href="https://stackoverflow.com/questions/60875183/how-to-define-a-functions-argument-type-dependent-on-string-argument-in-typescr">How to define a function&#39;s argument type dependent on string argument in Typescript?</a></li>
  <li><a href="https://stackoverflow.com/questions/48232339/typescript-make-one-parameter-type-depend-on-the-other-parameter">Typescript make one parameter type depend on the other parameter</a></li>
  <li><a href="https://stackoverflow.com/questions/51488717/declaring-dependent-argument-types-for-optional-arguments-with-conditional-types">Declaring dependent argument types for optional arguments with conditional types</a></li>
  <li><a href="https://stackoverflow.com/questions/52477947/typescript-correctly-typing-function-parameter-that-depends-on-property-in-the">Typescript. Correctly typing function parameter that depends on property in the same object literal</a></li>
  </ul>