We could add even all of these properties. We can go even deeper on this, if you want to. What you end up with is a really pure, just the good stuff parsing thing.ġ:16 What this means is you can get really, really cool. If we add eye_color, which is z.string, then what this is going to do is it's going to add eye_color onto the bottom here.Ġ:58 If we actually console.log the parsedData here - there we go - you'll notice that it actually strips out all of the keys it doesn't understand too. Zod understands the structure of the object here.Ġ:41 If we do the same thing we did last time and just console.log the data here, then we're going to get all our keys. parsedData, it's actually typed in the correct way. This data, now, it's typed as any in this position. It does it very effectively.Ġ:24 Here, what we're doing is we're basically using this to understand data, here. You can see again how Zod really, really copies what TypeScript does. If we wanted to do the same thing in TypeScript, we would say, "PersonResultType." We'd say, "name string," here. z.object is a tool that you can use to construct objects. Matt Pocock: 0:00 The solution here then is to change PersonResult here into a z.object.
0 Comments
Leave a Reply. |