jquense / yup

Dead simple Object schema validation
MIT License
22.9k stars 934 forks source link

`.partial()` doesn't seem to be working (1.0.0-beta.2) #1598

Closed zschiller closed 2 years ago

zschiller commented 2 years ago
const test = schema.object({
  test: schema.string().required(),
});

const partial = test.partial();

partial.validateSync({});

This throws the following runtime error:

ValidationError: test is a required field

I would expect that .partial() makes all the fields optional, am I using it wrong here somehow?

jquense commented 2 years ago

can you provide a repro with the template?

zschiller commented 2 years ago

@jquense https://codesandbox.io/s/thirsty-wildflower-7cspmv?file=/src/index.test.js

jquense commented 2 years ago

fixed in https://github.com/jquense/yup/releases/tag/v1.0.0-beta.3

knoefel commented 2 years ago

@jquense I'm not sure i'm doing something wrong, but for me partial isn't working correctly.

Edit stoic-water-w1e1d3

I thought validate should return the input, instead it's returning an object with all the defined props from the schema.

jquense commented 2 years ago

validate doesn't return the input, it returns the cast value: https://github.com/jquense/yup#object-schema-defaults