Skip to content

Commit

Permalink
fix: add optional message to nonNullable schema methods (#2119)
Browse files Browse the repository at this point in the history
  • Loading branch information
ranquild authored Dec 27, 2023
1 parent 5db2b2f commit 9e1df49
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 12 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ const parsedUser = await userSchema.validate(
- [`Schema.withMutation(builder: (current: Schema) => void): void`](#schemawithmutationbuilder-current-schema--void-void)
- [`Schema.default(value: any): Schema`](#schemadefaultvalue-any-schema)
- [`Schema.getDefault(options?: object): Any`](#schemagetdefaultoptions-object-any)
- [`Schema.nullable(): Schema`](#schemanullable-schema)
- [`Schema.nonNullable(): Schema`](#schemanonnullable-schema)
- [`Schema.nullable(message?: string | function): Schema`](#schemanullable-schema)
- [`Schema.nonNullable(message?: string | function): Schema`](#schemanonnullable-schema)
- [`Schema.defined(): Schema`](#schemadefined-schema)
- [`Schema.optional(): Schema`](#schemaoptional-schema)
- [`Schema.required(message?: string | function): Schema`](#schemarequiredmessage-string--function-schema)
Expand Down Expand Up @@ -946,7 +946,7 @@ yup.date.default(() => new Date()); // also helpful for defaults that change ove

Retrieve a previously set default value. `getDefault` will resolve any conditions that may alter the default. Optionally pass `options` with `context` (for more info on `context` see `Schema.validate`).

#### `Schema.nullable(): Schema`
#### `Schema.nullable(message?: string | function): Schema`

Indicates that `null` is a valid value for the schema. Without `nullable()`
`null` is treated as a different type and will fail `Schema.isType()` checks.
Expand All @@ -959,7 +959,7 @@ schema.cast(null); // null
InferType<typeof schema>; // number | null
```

#### `Schema.nonNullable(): Schema`
#### `Schema.nonNullable(message?: string | function): Schema`

The opposite of `nullable`, removes `null` from valid type values for the schema.
**Schema are non nullable by default**.
Expand Down
4 changes: 3 additions & 1 deletion src/array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,9 @@ export default interface ArraySchema<
notRequired(): ArraySchema<Maybe<TIn>, TContext, TDefault, TFlags>;

nullable(msg?: Message): ArraySchema<TIn | null, TContext, TDefault, TFlags>;
nonNullable(): ArraySchema<NotNull<TIn>, TContext, TDefault, TFlags>;
nonNullable(
msg?: Message,
): ArraySchema<NotNull<TIn>, TContext, TDefault, TFlags>;

strip(
enabled: false,
Expand Down
4 changes: 3 additions & 1 deletion src/date.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,9 @@ export default interface DateSchema<
notRequired(): DateSchema<Maybe<TType>, TContext, TDefault, TFlags>;

nullable(msg?: Message): DateSchema<TType | null, TContext, TDefault, TFlags>;
nonNullable(): DateSchema<NotNull<TType>, TContext, TDefault, TFlags>;
nonNullable(
msg?: Message,
): DateSchema<NotNull<TType>, TContext, TDefault, TFlags>;

strip(
enabled: false,
Expand Down
4 changes: 3 additions & 1 deletion src/mixed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ export default interface MixedSchema<
msg?: Message,
): MixedSchema<TType | null, TContext, TDefault, TFlags>;

nonNullable(): MixedSchema<Exclude<TType, null>, TContext, TDefault, TFlags>;
nonNullable(
msg?: Message,
): MixedSchema<Exclude<TType, null>, TContext, TDefault, TFlags>;

strip(
enabled: false,
Expand Down
4 changes: 3 additions & 1 deletion src/number.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,9 @@ export default interface NumberSchema<
nullable(
msg?: Message,
): NumberSchema<TType | null, TContext, TDefault, TFlags>;
nonNullable(): NumberSchema<NotNull<TType>, TContext, TDefault, TFlags>;
nonNullable(
msg?: Message,
): NumberSchema<NotNull<TType>, TContext, TDefault, TFlags>;

strip(
enabled: false,
Expand Down
4 changes: 3 additions & 1 deletion src/object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,9 @@ export default interface ObjectSchema<
notRequired(): ObjectSchema<Maybe<TIn>, TContext, TDefault, TFlags>;

nullable(msg?: Message): ObjectSchema<TIn | null, TContext, TDefault, TFlags>;
nonNullable(): ObjectSchema<NotNull<TIn>, TContext, TDefault, TFlags>;
nonNullable(
msg?: Message,
): ObjectSchema<NotNull<TIn>, TContext, TDefault, TFlags>;

strip(
enabled: false,
Expand Down
6 changes: 4 additions & 2 deletions src/string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,9 +288,11 @@ export default interface StringSchema<
notRequired(): StringSchema<Maybe<TType>, TContext, TDefault, TFlags>;

nullable(
msg?: Message<any>,
msg?: Message,
): StringSchema<TType | null, TContext, TDefault, TFlags>;
nonNullable(): StringSchema<NotNull<TType>, TContext, TDefault, TFlags>;
nonNullable(
msg?: Message
): StringSchema<NotNull<TType>, TContext, TDefault, TFlags>;

strip(
enabled: false,
Expand Down
4 changes: 3 additions & 1 deletion src/tuple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ export default interface TupleSchema<
nullable(
msg?: Message,
): TupleSchema<TType | null, TContext, TDefault, TFlags>;
nonNullable(): TupleSchema<NotNull<TType>, TContext, TDefault, TFlags>;
nonNullable(
msg?: Message
): TupleSchema<NotNull<TType>, TContext, TDefault, TFlags>;

strip(
enabled: false,
Expand Down

0 comments on commit 9e1df49

Please sign in to comment.