Skip to content

Commit 7554bfc

Browse files
authored
feat: use internal yup types (#3123)
1 parent 335db53 commit 7554bfc

12 files changed

Lines changed: 32 additions & 40 deletions

File tree

docs/content/api/use-form.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ type useForm = (
128128

129129
<code-title level="4">
130130

131-
`validationSchema?: Record<string, string | Function> | YupObjectSchema`
131+
`validationSchema?: Record<string, string | Function> | Yup.ShapeOf<T>`
132132

133133
</code-title>
134134

docs/content/guide/composition-api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ import { useForm } from 'vee-validate';
157157
import * as yup from 'yup';
158158

159159
const { ... } = useForm({
160-
validationSchema: yup.object().shape({
160+
validationSchema: yup.object({
161161
email: yup.string().required().email(),
162162
password: yup.string().required().min(3),
163163
})

docs/content/guide/handling-forms.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export default {
4949
Field,
5050
},
5151
data() {
52-
const schema = yup.object().shape({
52+
const schema = yup.object({
5353
name: yup.string().required(),
5454
email: yup.string().required().email(),
5555
password: yup.string().required().min(8),
@@ -88,7 +88,7 @@ export default {
8888
Field,
8989
},
9090
data() {
91-
const schema = yup.object().shape({
91+
const schema = yup.object({
9292
name: yup.string().required(),
9393
email: yup.string().required().email(),
9494
password: yup.string().required().min(8),
@@ -163,7 +163,7 @@ export default {
163163
Field,
164164
},
165165
data() {
166-
const schema = yup.object().shape({
166+
const schema = yup.object({
167167
name: yup.string().required(),
168168
email: yup.string().required().email(),
169169
password: yup.string().required().min(8),
@@ -211,7 +211,7 @@ export default {
211211
Field,
212212
},
213213
data() {
214-
const schema = yup.object().shape({
214+
const schema = yup.object({
215215
name: yup.string().required(),
216216
email: yup.string().required().email(),
217217
password: yup.string().required().min(8),
@@ -297,7 +297,7 @@ export default {
297297
},
298298
data() {
299299
// Validation Schema
300-
const schema = yup.object().shape({
300+
const schema = yup.object({
301301
name: yup.string().required(),
302302
email: yup.string().required().email(),
303303
password: yup.string().required().min(8),
@@ -462,7 +462,7 @@ export default {
462462
Field,
463463
},
464464
data() {
465-
const schema = yup.object().shape({
465+
const schema = yup.object({
466466
name: yup.string().required(),
467467
email: yup.string().required().email(),
468468
password: yup.string().required().min(8),
@@ -525,7 +525,7 @@ export default {
525525
Field,
526526
},
527527
data() {
528-
const schema = yup.object().shape({
528+
const schema = yup.object({
529529
// ...
530530
});
531531
@@ -591,7 +591,7 @@ export default {
591591
Field,
592592
},
593593
data() {
594-
const schema = yup.object().shape({
594+
const schema = yup.object({
595595
// ...
596596
});
597597

docs/content/guide/validation.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ export default {
142142
Fortunately there is already a very neat way to build validation schemas for your forms by using `yup`, it allows you create validation objects like this:
143143

144144
```js
145-
const schema = yup.object().shape({
145+
const schema = yup.object({
146146
email: yup.string().required().email(),
147147
name: yup.string().required(),
148148
password: yup.string().required().min(8),
@@ -174,7 +174,7 @@ export default {
174174
Field,
175175
},
176176
data() {
177-
const schema = yup.object().shape({
177+
const schema = yup.object({
178178
email: yup.string().required().email(),
179179
password: yup.string().required().min(8),
180180
});
@@ -398,7 +398,7 @@ You can do this in two ways depending on which validators you are using (yup or
398398
With yup it is very straightforward, you just need to call `label()` after defining your field's validations either in field level or form level:
399399

400400
```js
401-
const schema = Yup.object().shape({
401+
const schema = Yup.object({
402402
email_addr: Yup.string().email().required().label('Email Address'),
403403
acc_pazzword: Yup.string().min(5).required().label('Your Password'),
404404
});

docs/content/tutorials/best-practices.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ vee-validate's entire core size is very small, but the same can't be said about
1313
```js
1414
import * as yup from 'yup';
1515

16-
const schema = yup.object().shape({
16+
const schema = yup.object({
1717
email: yup.string().email(),
1818
// ...
1919
});
@@ -24,7 +24,7 @@ Instead you can leverage your bundler's tree-shaking capabilities and only impor
2424
```js
2525
import { object, string } as yup from 'yup';
2626

27-
const schema = object().shape({
27+
const schema = object({
2828
email: string().email(),
2929
// ...
3030
});
@@ -39,7 +39,7 @@ In most examples you probably noticed something like this:
3939
```js
4040
{
4141
data() {
42-
const schema = yup.object().shape({
42+
const schema = yup.object({
4343
email: yup.string().required().email(),
4444
password: yup.string().required().min(8),
4545
});
@@ -59,7 +59,7 @@ Instead you could either use `setup` instead of your data or [`markRaw`](https:/
5959
{
6060
setup() {
6161
// Non-reactive because it was not explicitly defined with `reactive` or `ref`
62-
const schema = yup.object().shape({
62+
const schema = yup.object({
6363
email: yup.string().required().email(),
6464
password: yup.string().required().min(8),
6565
});
@@ -77,7 +77,7 @@ import { markRaw } from 'vue';
7777
{
7878
data() {
7979
// Non-reactive because it was explicitly defined with `markRaw`
80-
const schema = markRaw(yup.object().shape({
80+
const schema = markRaw(yup.object({
8181
email: yup.string().required().email(),
8282
password: yup.string().required().min(8),
8383
}));

docs/content/tutorials/dynamic-form-generator.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ const formSchema = {
259259
fields: [
260260
// ...
261261
],
262-
+ validation: yup.object().shape({
262+
+ validation: yup.object({
263263
+ email: yup.string().email().required(),
264264
+ name: yup.string().required(),
265265
+ password: yup.string().min(8).required(),
@@ -322,7 +322,7 @@ const formSchema = {
322322
fields: [
323323
// ...
324324
],
325-
validation: yup.object().shape({
325+
validation: yup.object({
326326
// ...
327327
}),
328328
+ values: {

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
"@commitlint/cli": "^11.0.0",
2323
"@commitlint/config-conventional": "^11.0.0",
2424
"@types/jest": "^26.0.19",
25-
"@types/yup": "^0.29.11",
2625
"@typescript-eslint/eslint-plugin": "^4.12.0",
2726
"@typescript-eslint/parser": "^4.12.0",
2827
"chalk": "^4.1.0",

packages/vee-validate/src/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ComputedRef, Ref } from 'vue';
2-
import { ObjectSchema } from 'yup';
2+
import { SchemaOf } from 'yup';
33

44
export interface ValidationResult {
55
errors: string[];
@@ -75,7 +75,7 @@ export interface FormContext<TValues extends Record<string, any> = Record<string
7575
values: TValues;
7676
fields: ComputedRef<Record<keyof TValues, any>>;
7777
submitCount: Ref<number>;
78-
schema?: Record<keyof TValues, GenericValidateFunction | string | Record<string, any>> | ObjectSchema<TValues>;
78+
schema?: Record<keyof TValues, GenericValidateFunction | string | Record<string, any>> | SchemaOf<TValues>;
7979
validateSchema?: (shouldMutate?: boolean) => Promise<Record<keyof TValues, ValidationResult>>;
8080
validate(): Promise<FormValidationResult<TValues>>;
8181
meta: ComputedRef<{

packages/vee-validate/src/useForm.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { computed, ref, Ref, provide, reactive, onMounted, isRef, watch, unref, nextTick } from 'vue';
2-
import type { ObjectSchema, ValidationError } from 'yup';
2+
import type { SchemaOf, ValidationError } from 'yup';
33
import type { useField } from './useField';
44
import {
55
FieldMeta,
@@ -16,9 +16,7 @@ import { getFromPath, isYupValidator, keysOf, resolveNextCheckboxValue, setInPat
1616
import { FormErrorsSymbol, FormContextSymbol, FormInitialValuesSymbol } from './symbols';
1717

1818
interface FormOptions<TValues extends Record<string, any>> {
19-
validationSchema?:
20-
| Record<keyof TValues, GenericValidateFunction | string | Record<string, any>>
21-
| ObjectSchema<TValues>;
19+
validationSchema?: Record<keyof TValues, GenericValidateFunction | string | Record<string, any>> | SchemaOf<TValues>;
2220
initialValues?: MaybeReactive<TValues>;
2321
initialErrors?: Record<keyof TValues, string | undefined>;
2422
initialTouched?: Record<keyof TValues, boolean>;

packages/vee-validate/tests/Form.spec.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ describe('<Form />', () => {
344344
test('validation schema with yup', async () => {
345345
const wrapper = mountWithHoc({
346346
setup() {
347-
const schema = yup.object().shape({
347+
const schema = yup.object({
348348
email: yup.string().required().email(),
349349
password: yup.string().required().min(8),
350350
});
@@ -430,7 +430,7 @@ describe('<Form />', () => {
430430
test('cross field validation with yup schema', async () => {
431431
const wrapper = mountWithHoc({
432432
setup() {
433-
const schema = yup.object().shape({
433+
const schema = yup.object({
434434
password: yup.string().required(),
435435
confirmation: yup.string().oneOf([yup.ref('password')], 'passwords must match'),
436436
});
@@ -826,7 +826,7 @@ describe('<Form />', () => {
826826
test('checkboxes with yup schema', async () => {
827827
const wrapper = mountWithHoc({
828828
setup() {
829-
const schema = yup.object().shape({
829+
const schema = yup.object({
830830
drink: yup.array().required().min(1),
831831
});
832832

@@ -878,7 +878,7 @@ describe('<Form />', () => {
878878
let drinks!: Ref<string[]>;
879879
const wrapper = mountWithHoc({
880880
setup() {
881-
const schema = yup.object().shape({
881+
const schema = yup.object({
882882
drink: yup.array().required().min(1),
883883
});
884884

@@ -1118,7 +1118,7 @@ describe('<Form />', () => {
11181118
test('validate fields on mount with validateOnMount = true', async () => {
11191119
const wrapper = mountWithHoc({
11201120
setup() {
1121-
const schema = yup.object().shape({
1121+
const schema = yup.object({
11221122
email: yup.string().required().email(),
11231123
password: yup.string().required().min(8),
11241124
});
@@ -1259,7 +1259,7 @@ describe('<Form />', () => {
12591259
const spy = jest.fn();
12601260
const wrapper = mountWithHoc({
12611261
setup() {
1262-
const schema = yup.object().shape({
1262+
const schema = yup.object({
12631263
email: yup.string().required().email(),
12641264
password: yup.string().required().min(8),
12651265
});
@@ -1311,7 +1311,7 @@ describe('<Form />', () => {
13111311
const spy = jest.fn();
13121312
const wrapper = mountWithHoc({
13131313
setup() {
1314-
const schema = yup.object().shape({
1314+
const schema = yup.object({
13151315
email: yup.string().required().email(),
13161316
password: yup.string().required().min(8),
13171317
});

0 commit comments

Comments
 (0)