Open oyershov opened 3 weeks ago
I found the relevant code, and since they used undefined extends T
, if they had used assertEqual<undefined, T>
, the optional situation wouldn't have occurred. So I believe this was intentional.
I have the same issue
Hellođź‘‹, I face an issue with the default behavior of
z.any()
andz.unknown()
schemas. I expect these fields to have consistant behavior in line with other supported schemes:required
after the type is inferred. The actual result is that these fields are optional.Question: Is the current behavior expected or is it a bug?
Unit test coverage that misses this case: https://github.com/colinhacks/zod/blob/main/src/__tests__/object.test.ts#L292
Type inference example (screenshot)
Code example: