News for hackers. Stuff that matters.
Re:Zod: TypeScript-first schema validation with static type ... by kaoD on Wednesday October 09, 2024 @01:39PM (#41790557)
Does/will this correctly handle `| undefined` vs `?`, i.e. correct behavior under `exactOptionalPropertyTypes`?

Zod doesn't (yet[0]) and it's been a pain point for me.

[0] https://github.com/colinhacks/zod/issues/635

Re:Zod: TypeScript-first schema validation with static type ... by x1000 on Wednesday October 09, 2024 @01:51PM (#41790712)
I ran into exactly same pain point which was enough to nullify the benefits of using zod at all.
Re:Zod: TypeScript-first schema validation with static type ... by aleclarsoniv on Wednesday October 09, 2024 @09:10PM (#41794549)
TypeBox[1] differentiates between optional and undefined.

[1]: https://github.com/sinclairzx81/typebox

Re:Zod: TypeScript-first schema validation with static type ... by gkiely on Thursday October 10, 2024 @09:49AM (#41798795)
It does: https://valibot.dev/guides/optionals/#use-in-objects

  import * as v from 'valibot';
  const OptionalKeySchema = v.object({ key: v.optional(v.string()) });
  type t1 = v.InferInput<typeof OptionalKeySchema>; // { key?: string }

  const UndefinedKeySchema = v.object({ key: v.undefinedable(v.string()) });
  type t2 = v.InferInput<typeof UndefinedKeySchema>; // { key: undefined }