Skip to content

Conversation

@colinhacks
Copy link
Owner

@colinhacks colinhacks commented Dec 31, 2025

Closes #5495 #635 #1510

I don't love this API but it's the best we've got at the moment. This is 100% opt-in. The classic .optional() will continue behaving as it always has.

const A = z.object({
  a: z.string().optional(),
  b: z.string().exactOptional(),
});

type A = z.infer<typeof A>;
// => {
//   a?: string | undefined;
//   b?: string;
// }

A.parse({}); // ✅
A.parse({ a: undefined }); // ✅
A.parse({ b: undefined }); // ❌

Trying to enable exact optionality via some kind of global config is too kludgey and footgunny, so it needed to be an explicit API.

Copy link
Contributor

@pullfrog pullfrog bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blocking issue: the non-JIT code path doesn't implement the same error suppression logic as the JIT path, which will cause test failures and incorrect runtime behavior when jitless mode is enabled.

Pullfrog  | Fix all ➔Fix 👍s ➔View workflow runpullfrog.com𝕏

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Cannot type { key?: string }, can only do { key?: string | undefined }

1 participant