Scott Trinh
Scott Trinh
Yeah, I agree with them that this is correct behavior and I'm not familiar with any way at all we could widen the type that is created to be explicitly...
> So now (TS 4.6+) it's no longer possible to define an ordinary Model class that corresponds to a discriminated union provided by zod schema. Isn't the model class: ```ts...
That's a nice compact syntax, but this is something that is already achievable with `transform` which can be pretty powerful with destructuring and can do quite a bit more than...
For context here, we use `unwrap` to mean unwrapping in more contexts than just unwrapping a nullable schema, so I think it would be a misnomer for us to alias...
Maybe something like this? ```ts z.union([ z.object({ value: z.string(), numberStyle: z.never() }), z.object({ value: z.number(), numberStyle: z.string().regex(abcdRegexp).optional() }, ]) ```
Basically you're making a true union not a discriminated union. If you want to make this easier to narrow on the typescript side you could transform and add a discriminant,...
This is similar to the idea behind "branded" types, which is discussed here: https://github.com/colinhacks/zod/issues/3#issuecomment-794459823 TL;DR you can get that with roughly: ```ts type Tagged = T & { __tag: Tag...
The major difficulty here is the TypeScript uses structural type rather than nominal typing so if something is structurally compatible, they are equivalent and the compiler doesn't treat them differently....
You can achieve this with a transform, but that means that you're going to have to "pick a random number or date to use as the default" in the case...
> but does transform happen before or after validation? It happens after input parsing, if that makes sense. The flow goes: ```mermaid flowchart LR A[input] --> B{Nullable?}; B -- null...