Skip to content

Union type descriptions prints as JSON when using zod #151

Open

Description

@snelusha

When defining inputs with union type, I've noticed that using z from the trpc-cli causes that CLI to print JSON-like type description (e.g. Any of: [{"type":"string"},{"type":"boolean"}] (default: false)), whereas using z from zod package produces much clearer, human-readable output (e.g. type: string or boolean (default: false)).

Using z from trpc-cli:

import { z } from "trpc-cli";

import { t } from "~/trpc";

export const init = t.procedure
  .input(
    z.object({
      type: z.string().or(z.boolean()),
    }),
  )
  .mutation(({ input }) => {
    console.log(input);
  });
Usage: index init [options]

Options:
  --type [value]   Any of: [{"type":"string"},{"type":"boolean"}] (default: false)
  -h, --help       display help for command

Using z from zod:

import { z } from "zod";

import { t } from "~/trpc";

export const init = t.procedure
  .input(
    z.object({
      type: z.string().or(z.boolean()),
    }),
  )
  .mutation(({ input }) => {
    console.log(input);
  });
Usage: index init [options]

Options:
  --type [value]   type: string or boolean (default: false)
  -h, --help       display help for command

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions