Scott Trinh
Scott Trinh
ZZod
Created by unnreaal on 11/4/2024 in #questions
unnreaal - tsconst schema = z.coerce.string()....
37 replies
ZZod
Created by unnreaal on 11/4/2024 in #questions
unnreaal - tsconst schema = z.coerce.string()....
in the meantime, do not: 1. Use optional, nullish, or nullable with z.coerce schemas 2. Use z.coerce schemas in a z.union 3. Probably other stuff.
37 replies
ZZod
Created by unnreaal on 11/4/2024 in #questions
unnreaal - tsconst schema = z.coerce.string()....
it is! we'll need to fix that.
37 replies
ZZod
Created by unnreaal on 11/4/2024 in #questions
unnreaal - tsconst schema = z.coerce.string()....
but it does for now, so just avoid it until we fix that.
37 replies
ZZod
Created by unnreaal on 11/4/2024 in #questions
unnreaal - tsconst schema = z.coerce.string()....
it should just not include an .optional method.
37 replies
ZZod
Created by unnreaal on 11/4/2024 in #questions
unnreaal - tsconst schema = z.coerce.string()....
yes
37 replies
ZZod
Created by unnreaal on 11/4/2024 in #questions
unnreaal - tsconst schema = z.coerce.string()....
yep! don't use optional for coerce schemas.
37 replies
ZZod
Created by unnreaal on 11/4/2024 in #questions
unnreaal - tsconst schema = z.coerce.string()....
no, your original (without the .optional) is string
37 replies
ZZod
Created by unnreaal on 11/4/2024 in #questions
unnreaal - tsconst schema = z.coerce.string()....
it should just not allow you to .optional() on a coerce schema.
37 replies
ZZod
Created by unnreaal on 11/4/2024 in #questions
unnreaal - tsconst schema = z.coerce.string()....
Nope: this is { name: string; }
37 replies
ZZod
Created by unnreaal on 11/4/2024 in #questions
unnreaal - tsconst schema = z.coerce.string()....
I mean that .optional should not be an option for coerce schemas.
37 replies
ZZod
Created by unnreaal on 11/4/2024 in #questions
unnreaal - tsconst schema = z.coerce.string()....
for instance, this is also supported, but doesn't work:
const schema = z.union([z.coerce.string(), z.coerce.number()]);
type Schema = z.output<typeof schema>;
// string | number
const schema = z.union([z.coerce.string(), z.coerce.number()]);
type Schema = z.output<typeof schema>;
// string | number
In actuality, it's always string at runtime.
37 replies
ZZod
Created by unnreaal on 11/4/2024 in #questions
unnreaal - tsconst schema = z.coerce.string()....
It's only wrong because .optional makes everything | undefined, but optional doesn't mean anything for z.coerce schemas, so it's "right" but only technically right.
37 replies