title: Restricting typescript string literal values based on interface
body: <p>I'm trying to restrict the possible values of a string based on the keys of an interface. This might not be the best way to, if you know of a better way please let me know.</p>
  <pre><code>interface Events {
    &quot;home&quot;: {
      &quot;button&quot;: &quot;press&quot;
    },
    &quot;contact&quot;: {
      &quot;button&quot;: &quot;press&quot;,
      &quot;button2&quot;: &quot;press&quot; | &quot;longpress&quot;,
    }
  }
  
  type EventName&lt;
    E = Events,
    Context extends Extract&lt;keyof E, string&gt; = Extract&lt;keyof E, string&gt;,
    Object extends Extract&lt;keyof E[Context], string&gt; = Extract&lt;keyof E[Context], string&gt;,
    Action extends string &amp; E[Context][Object] = E[Context][Object],
    &gt; = `${Context}-${Object}-${Action}`
  
  
  const works: EventName = &quot;home-button-press&quot;;
  const doesnt: EventName = &quot;home-button2-longpress&quot;;
  //    ^^^^^^ Error: Type '&quot;home-button2-longpress&quot;' is not assignable to type '&quot;home-button-press&quot; | &quot;contact-button-press&quot;'.
  </code></pre>
  <p>Is seems to only be allowing the intersection of the set of strings in both objects, where as I want to restrict the possible values based on the previous key.</p>