Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(readme): some typos and update ValidationError doc #2085

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ const parsedUser = await userSchema.validate(
- [`addMethod(schemaType: Schema, name: string, method: ()=> Schema): void`](#addmethodschematype-schema-name-string-method--schema-void)
- [`ref(path: string, options: { contextPrefix: string }): Ref`](#refpath-string-options--contextprefix-string--ref)
- [`lazy((value: any) => Schema): Lazy`](#lazyvalue-any--schema-lazy)
- [`ValidationError(errors: string | Array<string>, value: any, path: string)`](#validationerrorerrors-string--arraystring-value-any-path-string)
- [`ValidationError(errors: string | Array<string>, value?: any, path?: string, type?: string)`](#validationerrorerrors-string--arraystring-value-any-path-string)
- [`Schema`](#schema)
- [`Schema.clone(): Schema`](#schemaclone-schema)
- [`Schema.label(label: string): Schema`](#schemalabellabel-string-schema)
Expand Down Expand Up @@ -209,7 +209,7 @@ const reversedString = string()
Transforms form a "pipeline", where the value of a previous transform is piped into the next one.
When an input value is `undefined` yup will apply the schema default if it's configured.

> Watch out! values are not guaranteed to be valid types in transform functions. Previous transforms
> Watch out! Values are not guaranteed to be valid types in transform functions. Previous transforms
> may have failed. For example a number transform may be receive the input value, `NaN`, or a number.

### Validation: Tests
Expand Down Expand Up @@ -367,7 +367,7 @@ You can use TypeScript's interface merging behavior to extend the schema types
if needed. Type extensions should go in an "ambient" type definition file such as your
`globals.d.ts`. Remember to actually extend the yup type in your application code!

> Watch out! merging only works if the type definition is _exactly_ the same, including
> Watch out! Merging only works if the type definition is _exactly_ the same, including
> generics. Consult the yup source code for each type to ensure you are defining it correctly

```ts
Expand Down Expand Up @@ -602,15 +602,15 @@ let renderable = yup.lazy((value) => {
let renderables = array().of(renderable);
```

#### `ValidationError(errors: string | Array<string>, value: any, path: string)`
#### `ValidationError(errors: string | Array<string>, value?: any, path?: string, type?: string)`

Thrown on failed validations, with the following properties

- `name`: "ValidationError"
- `type`: the specific test type or test "name", that failed.
- `type`?: the specific test type or test "name", that failed.
- `value`: The field value that was tested;
- `params`?: The test inputs, such as max value, regex, etc;
- `path`: a string, indicating where there error was thrown. `path` is empty at the root level.
- `path`?: a string, indicating where there error was thrown. `path` is empty at the root level.
- `errors`: array of error messages
- `inner`: in the case of aggregate errors, inner is an array of `ValidationErrors` throw earlier in the
validation chain. When the `abortEarly` option is `false` this is where you can inspect each error thrown,
Expand Down Expand Up @@ -1176,7 +1176,7 @@ Options = {
// the validation error message
message: string;
// values passed to message for interpolation
params: ?object;
params: object;
// mark the test as exclusive, meaning only one test of the same name can be active at once
exclusive: boolean = false;
}
Expand Down Expand Up @@ -1290,7 +1290,7 @@ await schema.isValid('hello'); // => true

By default, the `cast` logic of `string` is to call `toString` on the value if it exists.

empty values are not coerced (use `ensure()` to coerce empty values to empty strings).
Empty values are not coerced (use `ensure()` to coerce empty values to empty strings).

Failed casts return the input value.

Expand Down Expand Up @@ -1461,7 +1461,7 @@ let schema = yup.date();
await schema.isValid(new Date()); // => true
```

The default `cast` logic of `date` is pass the value to the `Date` constructor, failing that, it will attempt
The default `cast` logic of `date` is to pass the value to the `Date` constructor. Failing that, it will attempt
to parse the date as an ISO date string.

Failed casts return an invalid Date.
Expand Down Expand Up @@ -1569,7 +1569,7 @@ await schema.validate(['James', -24]); // => ValidationError: age must be a posi
InferType<typeof schema> // [string, number] | undefined
```

tuples have no default casting behavior.
Tuples have no default casting behavior.

### object

Expand All @@ -1585,11 +1585,11 @@ yup.object({
});
```

object schema do not have any default transforms applied.
Object schema do not have any default transforms applied.

#### Object schema defaults

Object schema come with a default value already set, which "builds" out the object shape, a
Object schema come with a default value already set, which "builds" out the object shape, and
sets any defaults for fields:

```js
Expand All @@ -1602,7 +1602,7 @@ schema.default(); // -> { name: '' }

This may be a bit surprising, but is usually helpful since it allows large, nested
schema to create default values that fill out the whole shape and not just the root object. There is
one gotcha! though. For nested object schema that are optional but include non optional fields
one gotcha! though. Nested object schema that are optional but include non optional fields
may fail in unexpected ways:

```js
Expand All @@ -1625,7 +1625,7 @@ During the validation phase `names` exists, and is validated, finding `names.fir
If you wish to avoid this behavior do one of the following:

- Set the nested default to undefined: `names.default(undefined)`
- mark it nullable and default to null: `names.nullable().default(null)`
- Mark it nullable and default to null: `names.nullable().default(null)`

#### `object.shape(fields: object, noSortEdges?: Array<[string, string]>): Schema`

Expand Down