Union type descriptions prints as JSON when using zod
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 373
- Forks
- 13
- PR merge metrics
- No merged PRs in 30d
Description
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
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the CLI help output for a tRPC input using z.string().or(z.boolean()), comparing z from trpc-cli with z from zod. Trace the union type description path and verify that the resulting option text is human-readable rather than JSON-like, while preserving the default value.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100