Z
Zod12mo ago
Scott Trinh

TS Playground - An online editor for exp...

Like, look how nice this is: https://www.typescriptlang.org/play?#code/JYWwDg9gTgLgBAbzgLzgXzgMyhEcBEyEAJvgNwBQFAxhAHYDO8MApkwMrUAWLIAhnAC8KAHQQARgCsW1GAAok4vlABcougFcQ4llDkBKdPso16TLMAA2rKELisO3XnxHKofAJ4HKcX34D0-nAAegD8pozwlhAQANYaYHYOMJw8-CIgugDmLHLIYlIy8kiYMWr5TFDAdFkGRvoUfgFBYVQsAB6QsHDELJh8Gtb2bClO-JQdXfAIjRbWugA0s9FxCRRoQA
import { z } from "zod";

const testSchema = z.object({ bar: z.number() });

const filter = testSchema.array();
// ^?
const lookup = testSchema.merge(z.object({ foo: z.string() }))
// ^?

export default testSchema;
export {
filter,
lookup
}
import { z } from "zod";

const testSchema = z.object({ bar: z.number() });

const filter = testSchema.array();
// ^?
const lookup = testSchema.merge(z.object({ foo: z.string() }))
// ^?

export default testSchema;
export {
filter,
lookup
}
TS Playground - An online editor for exploring TypeScript and JavaS...
The Playground lets you write TypeScript or JavaScript online in a safe and sharable way.
2 Replies
Unknown User
Unknown User12mo ago
Message Not Public
Sign In & Join Server To View
Scott Trinh
Scott Trinh12mo ago
Yeah, totally reasonable to want to write some machinery here to cut down on the boilerplate. I don't have anything to add to help with your actual request for help, so I'll let someone else come help, but just know that similar to TypeScript interfaces/types, a little duplication can make things way easier to manage and maintain over time. I think it's doable with enough hacking, but as soon as you throw a union or a transform in there, it's back to the drawing board and more battling with types and wrappers.