title: Inlining Typescript generic gives different behavior
body: <p>I'm pretty new to Typescript but I found some very surprising behavior with generics that I cannot find a reasonable explanation to.
  Basically, I have a object of the form</p>
  <pre class="lang-js prettyprint-override"><code>const data = {
      &quot;a&quot;: {
          include: true,
      },
      &quot;b&quot;: {
          include: false,
      },
  };
  </code></pre>
  <p>and I'm trying to programmatically get a type consisting of all keys with <code>include == true</code>, (so the type <code>&quot;a&quot;</code> in this case). You can see my code below, with three attempts, one that works and two that fail (they give <code>never</code> instead).</p>
  <p>Why does inlining the definition of <code>IncludedKey2</code> in <code>Attempt1</code> change the result (see <code>Attempt2</code>).
  I think I understand why <code>Attempt2</code> and <code>Attempt3</code> fail (<code>(typeof data)[Keys][&quot;include&quot;]</code> is <code>boolean</code> which does not extend <code>true</code>), but then I don’t understand why <code>Attempt1</code> works.</p>
  <pre class="lang-js prettyprint-override"><code>const data = {
      &quot;a&quot;: {
          include: true,
      },
      &quot;b&quot;: {
          include: false,
      },
  } as const;
  
  type Keys = keyof (typeof data) // Keys = &quot;a&quot; | &quot;b&quot;
  type IncludedKey&lt;Id extends Keys&gt; =
      (typeof data)[Id][&quot;include&quot;] extends true
          ? Id : never
  
  // Different version of IncludedKey that uses a conditional type instead of a constrained type parameter
  type IncludedKey2&lt;Id&gt; = Id extends Keys ? IncludedKey&lt;Id&gt; : never
  
  // Works
  type Attempt1 = IncludedKey2&lt;Keys&gt;; // Attempt1 = &quot;a&quot;
  
  // Fails
  // Simple inlining of IncludedKey2
  type Attempt2 = Keys extends Keys ? IncludedKey&lt;Keys&gt; : never // Attempt2 = never
  type Attempt3 = IncludedKey&lt;Keys&gt; // Attempt3 = never
  </code></pre>
  <p>(<a href="https://www.typescriptlang.org/play?ssl=24&amp;ssc=54&amp;pln=1&amp;pc=1#code/MYewdgzgLgBAJgQygmBeGBvAsAKAJABECBAXJrnngJZjAA2ArnAKZlQBODzANBQL698BAEaly+arUYsyAMwR0IPfoL4wEEGKEhQA3LlxQAngAdmMANLMjm9AGtrIWTAAUxs0-hIEAShgB6f0trWxgiAhgAHzDRQ1NzAEkpJmY4KyMAHgS4GGYADyhmMDhNdIgAPjQKN3jPRGQfAG1sgF1Gghp6FIIW3IKikpgOLgo8AH4YbJgyMGYAN2Z2AxxAmAARKllZRaLYBfYIKnAYTySuljTrIYALJBgGJU0UbTgqKCOwBSH4mBpoZgQOU8z3A0HYCBoqW+ZhgJgQ4IAtsxCkscO5EskLukAExZOCVdBTfKFYqlEIwCZnaSpdJ4yozeaLZarADqIHYdggcRhAEEoIUESYoABGNCTTE06y4srlXQBIJ8gVC0XocLMoIAMQhilwqwAylRBXRzDQ6DQaABzE7OKkpS5GbHc8yK5iCqDYsVlPokwZeykS+0ZGXTGCzfbymAut0e9Bhplon5RoUAZjFtqx1iDIUqqyTUFTscZ7CAA" rel="nofollow noreferrer">Playground</a>)</p>