Zod Section 10 exercises
solution

# Be Specific with Allowed Typesself.__wrap_balancer=(t,e,n)=>{n=n||document.querySelector(`[data-br="\${t}"]`);let o=n.parentElement,r=E=>n.style.maxWidth=E+"px";n.style.maxWidth="";let i=o.clientWidth,s=o.clientHeight,c=i/2,u=i,d;if(i){for(;c+1<u;)d=~~((c+u)/2),r(d),o.clientHeight==s?u=d:c=d;r(u*e+i*(1-e))}};self.__wrap_balancer(":Rhd9j6:",1)

There are two possible solutions to this challenge.

## One Solution: Use Unions & Literals

In the first solution, we'll use Zod's union method and pass in an array of literals for "private" and "public":

`const Form = z.object({ repoName: z.string(), privacyLevel: z.union([z.lite`

## Transcript

Matt Pocock: 0:00 This is the first solution. We've got z.union. Inside z.union we are passing an array. An array contains two possibilities. It contains a z.literal and another z.literal.

0:13 These `z.literals`, you can use them to represent anything. They represent to you some...Any sort of literal values inside typescripts, rather. You can't use them to represent objects. You can use them to represent numbers or strings or booleans.

0:27 What you end up with is if we say `type formType = z.infer<typeof Form>,` then we end up with private or public here. If I were to add another one to this in z.literal...What's the one down here, something-not-allowed. Then, what you get is this test would fail, of course, because we're specifically saying this thing is not allowed. We've now allowed it inside our union.

0:54 The other way to represent this, which is, I'd argue, a bit cleaner, is z.enum. This does exactly the same thing. It's just sort of under the hood. It's a sugar syntax for the other thing. I'm not sure you can parse it in z.literal here. Yeah.

1:09 You just parse in the literal values and it creates an enum for you. Rather, it doesn't create an enum as the way you think of it in TypeScript. It doesn't say PrivacyLevel private public like this. It doesn't do this. Instead, it creates a string literal type for you or a union type.

1:34 We've got `FormType = z.infer<typeof Form>.` Here, again, even though we're using a slightly different syntax, it's producing the same thing, private or public in a string union.