unable to connect to my kernels
ADD ISSUE DESCRIPTION HERE
Version: 1.93.1 Commit: 3542bd157b0ccc8bf732acdb03d4d69d85f48ea9 User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.1.1 Safari/605.1.15 Embedder: server-distro
@AndrewRayCode what is expected to resolve this issue?
@kemilbeltre There is a hack you can use in the linked Stackoverflow question. I couldn't use that for my app so I sadly had to refactor my core domain types to make the key optional. Zod doesn't seem to handle undefined types correctly which is ironic considering the author says Zod is better at type inference than Yup:
But it's very uncool for the inferred type to not actually reflect the actual type of the validator it came from.
There seems to be something fundamentally wrong with Zod, because this doesn't work either:
const stringOrUndefined = z.custom<string | undefined>(
(v) => typeof v === 'string' || v === undefined
);
const mySchema = z.object({ field: stringOrUndefined });
type Schema = z.infer<typeof mySchema>;
Results in
type Schema = {
field?: string | undefined;
}
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Doesn't seem stale given the reports (stackoverflow, this report, and https://github.com/colinhacks/zod/issues/2598)
any update?
I hope this gets some eyes soon. It is super valuable to be able to ensure a key is defined so that you can easily update all the references in a large codebase.
Hi, @AndrewRayCode. I'm Dosu, and I'm helping the Zod team manage their backlog and am marking this issue as stale.
Issue Summary:
- You reported that using
z.undefined()in unions causes TypeScript to infer keys as optional rather than required withundefinedallowed. - This affects both
.or()andz.union()usages, leading to inaccurate type representations. - You shared a workaround from Stack Overflow but had to refactor your types due to this behavior.
- Other users have shown interest in a fix, but the issue remains unresolved.
- The issue was previously marked stale, but you and others disagreed, noting related reports.
Next Steps:
- Please confirm if this issue is still relevant with the latest version of Zod; if so, you can keep the discussion open by commenting here.
- Otherwise, I will automatically close this issue in 7 days.
Thanks for your understanding and contribution!