39

Most Yup examples use the shape method, but I find the documentation a little hard to understand why this is the case, and exactly what the method does.

Can someone please explain the difference between a schema defined with Yup.object({...}) and Yup.object().shape({...})?

cubabit
  • 2,527
  • 3
  • 21
  • 34

1 Answers1

26

You can also pass a shape to the object constructor as a convenience.
yupobject documentation

Basically passing the schema to shape is just the long-form of passing it to the object constructor. Shape does however offer the benefit of chaining and overloading definitions in later chained methods. See yup.shape documentation

Mastacheata
  • 1,866
  • 2
  • 21
  • 32
  • Basically you can pass an initial shape to the constructor and then chain more shape() calls later. So object().shape({shape}) is really unnecessary. The documentation sort of explains this but in fragments; had read most of it. :) – tekHedd Apr 17 '23 at 20:21