title: How to map the field names of a Zod Discriminated Union
body: <p>Given a discriminated union</p>
  <pre><code>export const duParser = z.discriminatedUnion('type', [
    z.object({
      type: z.literal('a'),
      id: aParser,
    }),
    z.object({
      type: z.literal('b'),
      id: bParser,
    }),
  ]);
  </code></pre>
  <p>z.infer would be <code>{type: 'a', id: A} | {type: 'b', id: B}</code></p>
  <p>Now, I'd like to procure a parser and type out of it, such as:</p>
  <ol>
  <li><p>The union field (type) is mapped to another name (i.e. type -&gt; type2): <code>{type2: 'a', id: A} | {type2: 'b', id: B}</code></p>
  </li>
  <li><p>Other fields (although I agree it's bigger trouble, hence this division in the question) are mapped i.e. <code>{type: 'a', id2: A} | {type: 'b', id2: B}</code></p>
  </li>
  </ol>
  <p>The specific use case is that I have a generic parser into <code>{type: ..., id: ...}</code> which I'd like to merge with a flat structure parser, giving the discriminated union prefixed fields. The parser being flat is the requirement of the use case, where the parsed structure is a http query string: <code>rootField1=value1&amp;rootField2=value2&amp;subfieldId=subValue1&amp;subfieldType=a</code> where <code>subfieldId</code> and <code>subfieldType</code> are &quot;id&quot; and &quot;type&quot; of my original discriminatedUnion. Keeping them &quot;id&quot; and &quot;type&quot; isn't desirable since these attributes belong to another level of abstraction (i.e. the root entity could have its own id and type).</p>
  <p>Normally, I would do a nested structure here, but I wonder if flattening it together with mapping field names is possible in Zod.</p>