title: Typescript inferring union type instead of specified type
body: <p>I want to embed "metadata" into a type for use in creating a type-safe REST client. The idea is to use the type metadata in the link to infer the correct endpoint schema for use in the API call. E.g. </p>
  
  <pre><code>type Schema = {
    users: {
      GET: {
        query: { userId: string };
      };
    };
    posts: {
      POST: {};
    };
  };
  
  type User = {
    self: Link&lt;"users"&gt;;
  };
  
  const user: User = { self: "https://..." };
  
  http(user.self, "GET", { userId: 1 });
  </code></pre>
  
  <p>I was able to get this working with brute-force conditional types. </p>
  
  <p>E.g.</p>
  
  <pre class="lang-js prettyprint-override"><code>type Routes = "users" | "posts";
  type Verbs&lt;R&gt; = R extends "users" ? "GET" : never;
  type Query&lt;R, V&gt; = R extends "users"
    ? V extends "GET"
      ? { queryId: string }
      : never
    : never;
  </code></pre>
  
  <p>But this results in a normalized type model that would be difficult to enter manually. Instead I want to use a de-normalized type E.g.</p>
  
  <pre class="lang-js prettyprint-override"><code>type Schema = {
    users: {
      GET: {
        query: { userId: string };
      };
    };
    posts: {
      POST: {};
    };
  };
  </code></pre>
  
  <p>Using types like this:</p>
  
  <pre class="lang-js prettyprint-override"><code>type Query&lt;
    S,
    RN extends keyof S,
    VN extends keyof S[RN]
  &gt; = OpQuery&lt;S[RN][VN]&gt;;
  </code></pre>
  
  <p>I am able to get most of this working with the exception of the final and critical bit, inferring the route name from the link type:</p>
  
  <pre class="lang-js prettyprint-override"><code>type Schema = {
    users: {
      GET: {
        query: { userId: string };
      };
    };
    posts: {
      POST: {};
    };
  };
  
  type Link&lt;R extends keyof Schema&gt; = string;
  
  type LinkRouteName&lt;L&gt; = L extends Link&lt;infer R&gt; ? R : never;
  
  type name = LinkRouteName&lt;Link&lt;"users"&gt;&gt;;
  
  </code></pre>
  
  <p>expected: name === "users"</p>
  
  <p>actual: name === "users" | "posts"</p>