What are you trying to do that requires

What are you trying to do that requires mutating a schema?
8 Replies
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Scott Trinh
Scott TrinhOP2y ago
You can use let and reassign it dynamically.
let schema = z.string()

if (something) {
schema = schema.min(2) // or whatever
}
let schema = z.string()

if (something) {
schema = schema.min(2) // or whatever
}
But yeah if your needs are extremely dynamic it might make sense to do code generation like many x-to-Zod tools do.
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Scott Trinh
Scott TrinhOP2y ago
You just keep referencing schema and it'll be the latest version.
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Scott Trinh
Scott TrinhOP2y ago
Imagine it's like a literal like a number:
let n = 0
if (something) n = n + 1
if (somethingElse) n = n + 5
let n = 0
if (something) n = n + 1
if (somethingElse) n = n + 5
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Scott Trinh
Scott TrinhOP2y ago
Yeah your original example wasn't reassigning schema
Want results from more Discord servers?
Add your server