title: Typescript, declare a variable type must be key of an object
body: <p>Let's say I have an object like the following:</p>
  
  <pre><code>let obj = {
    method1: () =&gt; { return "method1 called" },
    method2: () =&gt; { return "method2 called" },
    method3: () =&gt; { return "method3 called" },
  }
  </code></pre>
  
  <p>I want to declare a variable, which value can only be one of the keys present in <code>obj</code>.<br>
  Manually, I can do it like this:  </p>
  
  <pre><code>let myVar : "method1" | "method2" | "method3";
  </code></pre>
  
  <p>But is there any way I can declare this in a dynamic way? So that any of the method I'd add in <code>obj</code> would be found as valid value for <code>myVar</code>.</p>