mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-05 15:27:05 +00:00
fix array.compact rejector type (#36449)
This commit is contained in:
committed by
Benjamin Lichtman
parent
e627b5b66b
commit
fc01ec61b4
Vendored
+8
-1
@@ -210,7 +210,13 @@ interface BasicArraySchema<T extends any[] | null | undefined>
|
||||
min(limit: number | Ref, message?: TestOptionsMessage): this;
|
||||
max(limit: number | Ref, message?: TestOptionsMessage): this;
|
||||
ensure(): this;
|
||||
compact(rejector?: (value: T, index: number, array: T[]) => boolean): this;
|
||||
compact(
|
||||
rejector?: (
|
||||
value: InferredArrayType<T>,
|
||||
index: number,
|
||||
array: Array<InferredArrayType<T>>
|
||||
) => boolean
|
||||
): this;
|
||||
}
|
||||
|
||||
export interface NotRequiredNullableArraySchema<T>
|
||||
@@ -506,3 +512,4 @@ type KeyOfUndefined<T> = {
|
||||
type RequiredProps<T> = Pick<T, Exclude<keyof T, KeyOfUndefined<T>>>;
|
||||
type NotRequiredProps<T> = Partial<Pick<T, KeyOfUndefined<T>>>;
|
||||
type InnerInferType<T> = NotRequiredProps<T> & RequiredProps<T>;
|
||||
type InferredArrayType<T> = T extends Array<infer U> ? U : T;
|
||||
|
||||
@@ -352,6 +352,15 @@ arrSchema.min(5, 'min');
|
||||
arrSchema.min(5, () => 'min');
|
||||
arrSchema.compact((value, index, array) => value === array[index]);
|
||||
|
||||
const arrOfObjSchema = yup.array().of(
|
||||
yup.object().shape({
|
||||
field: yup.number()
|
||||
})
|
||||
);
|
||||
arrOfObjSchema.compact((value, index, array) => {
|
||||
return value.field > 10 && array[index].field > 10;
|
||||
});
|
||||
|
||||
const arr = yup.array();
|
||||
const top = (<T>(x?: T): T => x!)();
|
||||
const validArr: yup.ArraySchema<typeof top> = arr;
|
||||
|
||||
Reference in New Issue
Block a user