Skip to content

Commit c677389

Browse files
committed
docs: when
1 parent 90790c3 commit c677389

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ let schema = object({
466466
loose: boolean(),
467467
bar: string().when('loose', {
468468
is: true,
469-
otherwise: (s) => s.strict(),
469+
otherwise: (schema) => schema.strict(),
470470
}),
471471
}),
472472
),
@@ -634,7 +634,7 @@ await schema.isValid(42); // => false
634634
await schema.isValid(new Date()); // => true
635635
```
636636

637-
#### `mixed.when(keys: string | Array<string>, builder: object | (value, schema)=> Schema): Schema`
637+
#### `mixed.when(keys: string | string[], builder: object | (values: any[], schema) => Schema): Schema`
638638

639639
Adjust the schema based on a sibling or sibling children fields. You can provide an object
640640
literal where the key `is` is value or a matcher function, `then` provides the true schema and/or
@@ -652,8 +652,8 @@ let schema = object({
652652
count: number()
653653
.when('isBig', {
654654
is: true, // alternatively: (val) => val == true
655-
then: yup.number().min(5),
656-
otherwise: yup.number().min(0),
655+
then: (schema) => schema..min(5),
656+
otherwise: (schema) => schema..min(0),
657657
})
658658
.when('$other', (other, schema) => (other === 4 ? schema.max(6) : schema)),
659659
});
@@ -669,8 +669,8 @@ let schema = object({
669669
isBig: boolean(),
670670
count: number().when(['isBig', 'isSpecial'], {
671671
is: true, // alternatively: (isBig, isSpecial) => isBig && isSpecial
672-
then: yup.number().min(5),
673-
otherwise: yup.number().min(0),
672+
then: (schema) => schema..min(5),
673+
otherwise: (schema) => schema..min(0),
674674
}),
675675
});
676676

0 commit comments

Comments
 (0)