title: Typed Zod combinator with dynamic field name
body: <p>My XML to JSON library emits <code>{MyKey: T}</code> for one-element lists, and <code>{MyKey: T[]}</code> for multi-element lists. The corresponding TypeScript type is <code>type XmlJsonArray&lt;T, element extends string&gt; = Record&lt;element, T | T[]&gt;</code>. I've used the following to implement it as a Zod schema:</p>
  <pre class="lang-js prettyprint-override"><code>const XmlJsonArray = &lt;T, element extends string&gt;(element: element, schema: z.Schema&lt;T&gt;) =&gt; {
    // TODO what is the idiomatic approach here?
    const outerSchema: Record&lt;element, z.Schema&lt;T | T[]&gt;&gt; = {} as any;
    outerSchema[element] = z.union([schema, z.array(schema)]);
    return z.object(outerSchema);
  };
  </code></pre>
  <p>Is there a way to do this without using <code>any</code>?</p>