4 ms·
Possibly stupid question, but why does the dog array validate: const dogsList = z.array(dogSchema); dogSchema.parse([ { name: 'Cujo', neutered: null },
by chris_st 7y ago
Possibly stupid question, but why does the dog array validate:
const dogsList = z.array(dogSchema);
dogSchema.parse([
{ name: 'Cujo', neutered: null },
{ name: 'Fido', age: 4, neutered: true },
]); // passes
Since 'Cujo' doesn't have an age? Assuming it's the same dogSchema as in the previous block, age is required, right?
Oh, and a minor typo: This lets you confidently This way you can confidently....
- colinmcd 7y agoWhoops! Should be `dogsList.parse(...)`. Also fixed the other typo :) Thanks!!
- tobr 7y agoI don’t want to derail the thread, but just a heads up: the layout is very broken on my phone (iPhone). The text is clipped on the left side which basically makes the article unreadable!
- andy_ppp 7y agoSorry to be a pain but even a few rules (even resetting some things) would make it much easier to read on mobile!
- colinmcd 7y agoFixed! I'd done exactly zero testing on mobile (built the site from scratch yesterday).
- deleted 7y ago[deleted]
- colinmcd 7y agoAh I see I misread your comment. You're right, Cujo also shouldn't have validated. In a previous version of the post `neutered` was nullable and `age` was optional, but I decided to save the discussion of nullables/optional until later so I changed it. Good catch!!