Skip to content

Commit

Permalink
fix(types): Array required() and defined() will no longer return any (#…
Browse files Browse the repository at this point in the history
…1256)

* Array required() and defined() will no longer return any

* Array required and defined test improvements

* Array nullable() will not return any + use ESLint comment to test array defined and array required
  • Loading branch information
bart-opplane authored Feb 17, 2021
1 parent da23aea commit 52e5876
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,20 @@ export default class ArraySchema<
if (this.innerType) base.innerType = this.innerType.describe();
return base;
}

nullable(isNullable?: true): ArraySchema<T, C, TIn | null>;
nullable(isNullable: false): ArraySchema<T, C, Exclude<TIn, null>>;
nullable(isNullable = true): ArraySchema<T, C, TIn | null> {
return super.nullable(isNullable as any);
}

defined(): DefinedArraySchema<T, C, TIn> {
return super.defined();
}

required(msg?: MixedLocale['required']): RequiredArraySchema<T, C, TIn> {
return super.required(msg);
}
}

create.prototype = ArraySchema.prototype;
Expand Down
14 changes: 14 additions & 0 deletions test/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,20 @@ SchemaOf: {
const _c1 = array(number())
.concat(array(number()).required())
.validateSync([]);

// $ExpectType AssertsShape<{ a: RequiredNumberSchema<number | undefined, Record<string, any>>; }>[] | null
const _definedArray: Array<{ a: number }> | null = array()
.of(object({ a: number().required() }))
.nullable()
.defined()
.validateSync([]);

// $ExpectType AssertsShape<{ a: RequiredNumberSchema<number | undefined, Record<string, any>>; }>[]
const _requiredArray: Array<{ a: number }> = array()
.of(object({ a: number().required() }))
.nullable()
.required()
.validateSync([]);
}

{
Expand Down

0 comments on commit 52e5876

Please sign in to comment.