Created
May 24, 2018 22:42
-
-
Save lfantone/e73634b28eae1489757f493961e12961 to your computer and use it in GitHub Desktop.
Yup's Flow types
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
declare module 'yup' { | |
declare type ValidateOptions = { | |
strict?: boolean, | |
abortEarly?: boolean, | |
stripUnknown?: boolean, | |
recursive?: boolean, | |
context?: any | |
}; | |
declare type ValidationError = { | |
errors: string | string[], | |
value: any, | |
path: string, | |
type?: any | |
}; | |
declare type SchemaDescription = { | |
type: string, | |
label: string, | |
meta: string, | |
tests: string[] | |
}; | |
declare type WhenOptionsBuilder<T> = { | |
(value: any, schema: T): T, | |
(v1: any, v2: any, schema: T): T, | |
(v1: any, v2: any, v3: any, schema: T): T, | |
(v1: any, v2: any, v3: any, v4: any, schema: T): T | |
}; | |
declare type WhenOptions<T> = | |
| WhenOptionsBuilder<T> | |
| { | |
is: boolean | ((value: any) => boolean), | |
then: any, | |
otherwise: any | |
}; | |
declare type TestOptions = { | |
name?: string, | |
test: (value: any) => boolean, | |
message?: string, | |
params?: any, | |
exclusive?: boolean | |
}; | |
declare type TransformFunction<T> = ( | |
schema: T, | |
value: any, | |
originalValue: any | |
) => any; | |
declare type Schema = { | |
shape(fields: any, noSortEdges?: Array<[string, string]>): Schema, | |
clone(): Schema, | |
label(label: string): Schema, | |
meta(metadata: any): Schema, | |
meta(): any, | |
describe(): SchemaDescription, | |
concat(schema: Schema): Schema, | |
validate<U>( | |
value: U, | |
options?: ValidateOptions | |
): Promise<ValidationError | U>, | |
validateSync<U>(value: U, options?: ValidateOptions): ValidationError | U, | |
isValid(value: any, options?: any): Promise<boolean>, | |
isValidSync(value: any, options?: any): boolean, | |
cast(value: any, options?: any): any, | |
isType(value: any): boolean, | |
strict(isStrict: boolean): Schema, | |
strip(strip: boolean): Schema, | |
withMutation(fn: (current: Schema) => void): void, | |
default(value?: any): Schema, | |
nullable(isNullable: boolean): Schema, | |
required(message?: string): Schema, | |
typeError(message?: string): Schema, | |
oneOf(arrayOfValues: any[], message?: string): Schema, | |
notOneOf(arrayOfValues: any[], message?: string): Schema, | |
when(keys: string | any[], builder: WhenOptions<Schema>): Schema, | |
test( | |
name: string, | |
message: string, | |
test: (value?: any) => boolean, | |
callbackStyleAsync?: boolean | |
): Schema, | |
test(options: TestOptions): Schema, | |
transform(fn: TransformFunction<Schema>): Schema | |
}; | |
declare type Yup = { | |
object(): Schema, | |
string(): Schema, | |
date(): Schema, | |
mixed(): Schema, | |
number(): Schema, | |
boolean(): Schema, | |
array(): Schema, | |
object(): Schema | |
}; | |
declare module.exports: Yup; | |
} |
A little bit more types
declare type Yup = {
reach(schema: Schema, path: string, value?: Object, context?: Object): Schema,
addMethod(schemaType: Schema, name: string, method: () => Schema): void,
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello @lfantone ! Thanks a lot for these types ! Do you know if they are available on flow-typed ?
yarn flow-typed install yup
doesn't lead to expected result..