Skip to content
Discussion options

You must be logged in to vote

@jakub-msqt , Consider either:

factory.build({
  output: z.object({
    hasNoChanges: z.literal(true),
  }).or(z.object(fields)),
});

OR

factory.build({
  output: z.object(fields).partial(), // <— makes all props optional
});

and then handle it accordingly in a ResultHandler.
First variant might be easier to handle thanx to explicit hasNoChanges in output.

Your z.union() is also fine.

but it doesn't let me return e.g. empty object and non-empty object.

I'm not sure I get this. How exactly it does not let you? I didn't have any issues with your code sample.

Replies: 1 comment 9 replies

Comment options

You must be logged in to vote
9 replies
@jakub-msqt
Comment options

@RobinTail
Comment options

@jakub-msqt
Comment options

@jakub-msqt
Comment options

@RobinTail
Comment options

Answer selected by RobinTail
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants