Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

225
Views
What is the difference between z.optional(z.string()) and z.ostring() of zod?

To make any schema optional, I've seen that zod provides two methods: z.optional(z.string()) and z.ostring(). I wonder what is the difference between them? And what should I use for most cases?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Looking at the source code reveals that:

const ostring = () => stringType().optional();

And from the readme we know that:

const optionalString = z.string().optional(); // string | undefined

// equivalent to
z.optional(z.string());

So there is no difference

about 4 years ago · Juan Pablo Isaza Report

0

The two ways are the same.

z.ostring() and the like are shortcuts. They are equivalent in function to wrapping the normal type with z.optional() or chaining .optional(). In fact, they are implemented internally using the chained .optional().

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!