mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-06-28 06:10:06 +00:00
committed by
Ryan Cavanaugh
parent
d3a74b87d7
commit
bbb62a63f4
10
types/yup/index.d.ts
vendored
10
types/yup/index.d.ts
vendored
@@ -5,7 +5,7 @@
|
||||
// TypeScript Version: 2.2
|
||||
|
||||
export function reach(schema: Schema, path: string, value?: any, context?: any): Schema;
|
||||
export function addMethod(schemaType: Schema, name: string, method: (this: Schema) => Schema): void;
|
||||
export function addMethod<T extends Schema>(schemaCtor: AnySchemaConstructor, name: string, method: (this: T, ...args: any[]) => T): void;
|
||||
export function ref(path: string, options?: { contextPrefix: string }): Ref;
|
||||
export function lazy(fn: (value: any) => Schema): Lazy;
|
||||
export function ValidationError(errors: string | string[], value: any, path: string, type?: any): ValidationError;
|
||||
@@ -19,6 +19,14 @@ export const date: DateSchemaConstructor;
|
||||
export const array: ArraySchemaConstructor;
|
||||
export const object: ObjectSchemaConstructor;
|
||||
|
||||
export type AnySchemaConstructor = MixedSchemaConstructor
|
||||
| StringSchemaConstructor
|
||||
| NumberSchemaConstructor
|
||||
| BooleanSchemaConstructor
|
||||
| DateSchemaConstructor
|
||||
| ArraySchemaConstructor
|
||||
| ObjectSchemaConstructor;
|
||||
|
||||
export interface Schema {
|
||||
clone(): this;
|
||||
label(label: string): this;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import * as yup from 'yup';
|
||||
// tslint:disable-next-line:no-duplicate-imports
|
||||
import { reach, date, Schema, ObjectSchema, ValidationError, MixedSchema, SchemaDescription, TestOptions, ValidateOptions } from 'yup';
|
||||
import { reach, date, Schema, ObjectSchema, ValidationError, MixedSchema, SchemaDescription, TestOptions, ValidateOptions, NumberSchema } from 'yup';
|
||||
|
||||
// reach function
|
||||
let schema = yup.object().shape({
|
||||
@@ -14,8 +14,11 @@ reach(schema, 'nested.arr.num');
|
||||
reach(schema, 'nested.arr[].num');
|
||||
|
||||
// addMethod function
|
||||
yup.addMethod(yup.date(), 'format', function(this: Schema) {
|
||||
return this.clone();
|
||||
yup.addMethod<NumberSchema>(yup.number, 'minimum', function(this, minValue: number, message: string) {
|
||||
return this.min(minValue, message);
|
||||
});
|
||||
yup.addMethod(yup.date, 'newMethod', function(this: yup.DateSchema, date: Date, message?: string) {
|
||||
return this.max(date, message);
|
||||
});
|
||||
|
||||
// ref function
|
||||
|
||||
Reference in New Issue
Block a user