@types/yup
Advanced tools
Comparing version 0.26.22 to 0.26.23
@@ -14,15 +14,11 @@ // Type definitions for yup 0.26 | ||
// Maurice de Beijer <https://github.com/mauricedb> | ||
// Kalley Powell <https://github.com/kalley> | ||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped | ||
// TypeScript Version: 2.8 | ||
// TypeScript Version: 3.1 | ||
export function reach<T>( | ||
schema: Schema<T>, | ||
path: string, | ||
value?: any, | ||
context?: any | ||
): Schema<T>; | ||
export function reach<T>(schema: Schema<T>, path: string, value?: any, context?: any): Schema<T>; | ||
export function addMethod<T extends Schema<any>>( | ||
schemaCtor: AnySchemaConstructor, | ||
name: string, | ||
method: (this: T, ...args: any[]) => T | ||
method: (this: T, ...args: any[]) => T, | ||
): void; | ||
@@ -52,5 +48,5 @@ export function ref(path: string, options?: { contextPrefix: string }): Ref; | ||
export type TestOptionsMessage = | ||
export type TestOptionsMessage<Extra extends Record<string, any> = {}, R = any> = | ||
| string | ||
| ((params: object & Partial<TestMessageParams>) => string); | ||
| ((params: Extra & Partial<TestMessageParams>) => R); | ||
@@ -78,17 +74,13 @@ export interface Schema<T> { | ||
typeError(message?: TestOptionsMessage): this; | ||
oneOf(arrayOfValues: Array<T | Ref>, message?: TestOptionsMessage): this; | ||
notOneOf(arrayOfValues: any[], message?: TestOptionsMessage): this; | ||
oneOf(arrayOfValues: Array<T | Ref | null>, message?: TestOptionsMessage<{ values: T | Ref }>): this; | ||
notOneOf(arrayOfValues: any[], message?: TestOptionsMessage<{ values: T | Ref }>): this; | ||
when(keys: string | any[], builder: WhenOptions<this>): this; | ||
test( | ||
name: string, | ||
message: | ||
| string | ||
| ((params: object & Partial<TestMessageParams>) => string), | ||
test: ( | ||
this: TestContext, | ||
value?: any | ||
) => boolean | ValidationError | Promise<boolean | ValidationError>, | ||
callbackStyleAsync?: boolean | ||
message: TestOptionsMessage, | ||
test: (this: TestContext, value?: any) => boolean | ValidationError | Promise<boolean | ValidationError>, | ||
callbackStyleAsync?: boolean, | ||
): this; | ||
test(options: TestOptions): this; | ||
// tslint:disable-next-line:no-unnecessary-generics | ||
test<P>(options: TestOptions<P>): this; | ||
transform(fn: TransformFunction<this>): this; | ||
@@ -111,3 +103,3 @@ } | ||
concat(schema: this): this; | ||
concat<U >(schema: MixedSchema<U>): MixedSchema<T | U>; | ||
concat<U>(schema: MixedSchema<U>): MixedSchema<T | U>; | ||
} | ||
@@ -120,15 +112,14 @@ | ||
export interface StringSchema<T extends string | null | undefined = string> | ||
extends Schema<T> { | ||
length(limit: number | Ref, message?: TestOptionsMessage): StringSchema<T>; | ||
min(limit: number | Ref, message?: TestOptionsMessage): StringSchema<T>; | ||
max(limit: number | Ref, message?: TestOptionsMessage): StringSchema<T>; | ||
export interface StringSchema<T extends string | null | undefined = string> extends Schema<T> { | ||
length(limit: number | Ref, message?: TestOptionsMessage<{ length: number | Ref }>): StringSchema<T>; | ||
min(limit: number | Ref, message?: TestOptionsMessage<{ min: number | Ref }>): StringSchema<T>; | ||
max(limit: number | Ref, message?: TestOptionsMessage<{ max: number | Ref }>): StringSchema<T>; | ||
matches( | ||
regex: RegExp, | ||
messageOrOptions?: | ||
| TestOptionsMessage | ||
| { message?: TestOptionsMessage; excludeEmptyString?: boolean } | ||
| TestOptionsMessage<{ regex: RegExp }> | ||
| { message?: TestOptionsMessage<{ regex: RegExp }>; excludeEmptyString?: boolean }, | ||
): StringSchema<T>; | ||
email(message?: TestOptionsMessage): StringSchema<T>; | ||
url(message?: TestOptionsMessage): StringSchema<T>; | ||
email(message?: TestOptionsMessage<{ regex: RegExp }>): StringSchema<T>; | ||
url(message?: TestOptionsMessage<{ regex: RegExp }>): StringSchema<T>; | ||
ensure(): StringSchema<T>; | ||
@@ -150,19 +141,12 @@ trim(message?: TestOptionsMessage): StringSchema<T>; | ||
export interface NumberSchema<T extends number | null | undefined = number> | ||
extends Schema<T> { | ||
min(limit: number | Ref, message?: TestOptionsMessage): NumberSchema<T>; | ||
max(limit: number | Ref, message?: TestOptionsMessage): NumberSchema<T>; | ||
lessThan( | ||
limit: number | Ref, | ||
message?: TestOptionsMessage | ||
): NumberSchema<T>; | ||
moreThan( | ||
limit: number | Ref, | ||
message?: TestOptionsMessage | ||
): NumberSchema<T>; | ||
positive(message?: TestOptionsMessage): NumberSchema<T>; | ||
negative(message?: TestOptionsMessage): NumberSchema<T>; | ||
export interface NumberSchema<T extends number | null | undefined = number> extends Schema<T> { | ||
min(limit: number | Ref, message?: TestOptionsMessage<{ min: number }>): NumberSchema<T>; | ||
max(limit: number | Ref, message?: TestOptionsMessage<{ max: number }>): NumberSchema<T>; | ||
lessThan(limit: number | Ref, message?: TestOptionsMessage<{ less: number }>): NumberSchema<T>; | ||
moreThan(limit: number | Ref, message?: TestOptionsMessage<{ more: number }>): NumberSchema<T>; | ||
positive(message?: TestOptionsMessage<{ more: number }>): NumberSchema<T>; | ||
negative(message?: TestOptionsMessage<{ less: number }>): NumberSchema<T>; | ||
integer(message?: TestOptionsMessage): NumberSchema<T>; | ||
truncate(): NumberSchema<T>; | ||
round(type: "floor" | "ceil" | "trunc" | "round"): NumberSchema<T>; | ||
round(type: 'floor' | 'ceil' | 'trunc' | 'round'): NumberSchema<T>; | ||
nullable(isNullable?: true): NumberSchema<T | null>; | ||
@@ -180,10 +164,7 @@ nullable(isNullable: false): NumberSchema<Exclude<T, null>>; | ||
export interface BooleanSchema<T extends boolean | null | undefined = boolean> | ||
extends Schema<T> { | ||
export interface BooleanSchema<T extends boolean | null | undefined = boolean> extends Schema<T> { | ||
nullable(isNullable?: true): BooleanSchema<T | null>; | ||
nullable(isNullable: false): BooleanSchema<Exclude<T, null>>; | ||
nullable(isNullable?: boolean): BooleanSchema<T>; | ||
required( | ||
message?: TestOptionsMessage | ||
): BooleanSchema<Exclude<T, undefined>>; | ||
required(message?: TestOptionsMessage): BooleanSchema<Exclude<T, undefined>>; | ||
notRequired(): BooleanSchema<T | undefined>; | ||
@@ -197,12 +178,5 @@ } | ||
export interface DateSchema<T extends Date | null | undefined = Date> | ||
extends Schema<T> { | ||
min( | ||
limit: Date | string | Ref, | ||
message?: TestOptionsMessage | ||
): DateSchema<T>; | ||
max( | ||
limit: Date | string | Ref, | ||
message?: TestOptionsMessage | ||
): DateSchema<T>; | ||
export interface DateSchema<T extends Date | null | undefined = Date> extends Schema<T> { | ||
min(limit: Date | string | Ref, message?: TestOptionsMessage<{ min: Date | string }>): DateSchema<T>; | ||
max(limit: Date | string | Ref, message?: TestOptionsMessage<{ max: Date | string }>): DateSchema<T>; | ||
nullable(isNullable?: true): DateSchema<T | null>; | ||
@@ -220,18 +194,12 @@ nullable(isNullable: false): DateSchema<Exclude<T, null>>; | ||
interface BasicArraySchema<T extends any[] | null | undefined> | ||
extends Schema<T> { | ||
min(limit: number | Ref, message?: TestOptionsMessage): this; | ||
max(limit: number | Ref, message?: TestOptionsMessage): this; | ||
interface BasicArraySchema<T extends any[] | null | undefined> extends Schema<T> { | ||
min(limit: number | Ref, message?: TestOptionsMessage<{ min: number }>): this; | ||
max(limit: number | Ref, message?: TestOptionsMessage<{ max: number }>): this; | ||
ensure(): this; | ||
compact( | ||
rejector?: ( | ||
value: InferredArrayType<T>, | ||
index: number, | ||
array: Array<InferredArrayType<T>> | ||
) => boolean | ||
rejector?: (value: InferredArrayType<T>, index: number, array: Array<InferredArrayType<T>>) => boolean, | ||
): this; | ||
} | ||
export interface NotRequiredNullableArraySchema<T> | ||
extends BasicArraySchema<T[] | null | undefined> { | ||
export interface NotRequiredNullableArraySchema<T> extends BasicArraySchema<T[] | null | undefined> { | ||
of<U>(type: Schema<U>): NotRequiredNullableArraySchema<U>; | ||
@@ -254,4 +222,3 @@ nullable(isNullable?: true): NotRequiredNullableArraySchema<T>; | ||
export interface NotRequiredArraySchema<T> | ||
extends BasicArraySchema<T[] | undefined> { | ||
export interface NotRequiredArraySchema<T> extends BasicArraySchema<T[] | undefined> { | ||
of<U>(type: Schema<U>): NotRequiredArraySchema<U>; | ||
@@ -274,3 +241,3 @@ nullable(isNullable?: true): NotRequiredNullableArraySchema<T>; | ||
export type ObjectSchemaDefinition<T extends object | null | undefined> = { | ||
[field in keyof T]: Schema<T[field]> | Ref | ||
[field in keyof T]: Schema<T[field]> | Ref; | ||
}; | ||
@@ -284,3 +251,3 @@ | ||
export type Shape<T extends object | null | undefined, U extends object> = { | ||
[P in keyof T]: P extends keyof U ? U[P] : T[P] | ||
[P in keyof T]: P extends keyof U ? U[P] : T[P]; | ||
} & | ||
@@ -294,13 +261,9 @@ U; | ||
export interface ObjectSchema<T extends object | null | undefined = object> | ||
extends Schema<T> { | ||
export interface ObjectSchema<T extends object | null | undefined = object> extends Schema<T> { | ||
shape<U extends object>( | ||
fields: ObjectSchemaDefinition<U>, | ||
noSortEdges?: Array<[string, string]> | ||
noSortEdges?: Array<[string, string]>, | ||
): ObjectSchema<Shape<T, U>>; | ||
from(fromKey: string, toKey: string, alias?: boolean): ObjectSchema<T>; | ||
noUnknown( | ||
onlyKnownKeys?: boolean, | ||
message?: TestOptionsMessage | ||
): ObjectSchema<T>; | ||
noUnknown(onlyKnownKeys?: boolean, message?: TestOptionsMessage): ObjectSchema<T>; | ||
transformKeys(callback: (key: any) => any): void; | ||
@@ -318,7 +281,3 @@ camelCase(): ObjectSchema<T>; | ||
export type TransformFunction<T> = ( | ||
this: T, | ||
value: any, | ||
originalValue: any | ||
) => any; | ||
export type TransformFunction<T> = (this: T, value: any, originalValue: any) => any; | ||
@@ -332,9 +291,3 @@ export interface WhenOptionsBuilderFunction<T> { | ||
export type WhenOptionsBuilderObjectIs = | ||
| ((...values: any[]) => boolean) | ||
| boolean | ||
| number | ||
| null | ||
| object | ||
| string; | ||
export type WhenOptionsBuilderObjectIs = ((...values: any[]) => boolean) | boolean | number | null | object | string; | ||
@@ -349,5 +302,3 @@ export type WhenOptionsBuilderObject = | ||
export type WhenOptions<T> = | ||
| WhenOptionsBuilderFunction<T> | ||
| WhenOptionsBuilderObject; | ||
export type WhenOptions<T> = WhenOptionsBuilderFunction<T> | WhenOptionsBuilderObject; | ||
@@ -360,6 +311,3 @@ export interface TestContext { | ||
resolve: (value: any) => any; | ||
createError: (params?: { | ||
path?: string; | ||
message?: string; | ||
}) => ValidationError; | ||
createError: (params?: { path?: string; message?: string }) => ValidationError; | ||
} | ||
@@ -397,3 +345,3 @@ | ||
export interface TestOptions { | ||
export interface TestOptions<P extends Record<string, any> = {}, R = any> { | ||
/** | ||
@@ -407,6 +355,3 @@ * Unique name identifying the test | ||
*/ | ||
test: ( | ||
this: TestContext, | ||
value: any | ||
) => boolean | ValidationError | Promise<boolean | ValidationError>; | ||
test: (this: TestContext, value: any) => boolean | ValidationError | Promise<boolean | ValidationError>; | ||
@@ -416,3 +361,3 @@ /** | ||
*/ | ||
message?: TestOptionsMessage; | ||
message?: TestOptionsMessage<P, R>; | ||
@@ -422,3 +367,3 @@ /** | ||
*/ | ||
params?: object; | ||
params?: P; | ||
@@ -465,13 +410,5 @@ /** | ||
static isError(err: any): err is ValidationError; | ||
static formatError( | ||
message: string | ((params?: any) => string), | ||
params?: any | ||
): string | ((params?: any) => string); | ||
static formatError(message: string | ((params?: any) => string), params?: any): string | ((params?: any) => string); | ||
constructor( | ||
errors: string | string[], | ||
value: any, | ||
path: string, | ||
type?: any | ||
); | ||
constructor(errors: string | string[], value: any, path: string, type?: any); | ||
} | ||
@@ -518,16 +455,22 @@ | ||
type MessageFromParameters<P extends unknown[]> = { | ||
[K in keyof P]: P[K] extends TestOptionsMessage<any> ? P[K] : never; | ||
}[number]; | ||
type MappedLocaleSchema<S extends Schema<any>> = { | ||
[key in keyof S]?: S[key] extends (...args: infer P) => any ? MessageFromParameters<Required<P>> : never; | ||
}; | ||
export interface LocaleObject { | ||
mixed?: { [key in keyof MixedSchema]?: string } & { notType?: LocaleValue }; | ||
string?: { [key in keyof StringSchema]?: string }; | ||
number?: { [key in keyof NumberSchema]?: string }; | ||
boolean?: { [key in keyof BooleanSchema]?: string }; | ||
bool?: { [key in keyof BooleanSchema]?: string }; | ||
date?: { [key in keyof DateSchema]?: string }; | ||
array?: { [key in keyof ArraySchema<any>]?: string }; | ||
object?: { [key in keyof ObjectSchema<any>]?: string }; | ||
mixed?: MappedLocaleSchema<MixedSchema> & { notType?: LocaleValue }; | ||
string?: MappedLocaleSchema<StringSchema>; | ||
number?: MappedLocaleSchema<NumberSchema>; | ||
boolean?: MappedLocaleSchema<BooleanSchema>; | ||
bool?: MappedLocaleSchema<BooleanSchema>; | ||
date?: MappedLocaleSchema<DateSchema>; | ||
array?: MappedLocaleSchema<ArraySchema<any>>; | ||
object?: MappedLocaleSchema<ObjectSchema<any>>; | ||
} | ||
export type InferType<T> = T extends Schema<infer P> | ||
? InnerInferType<P> | ||
: never; | ||
export type InferType<T> = T extends Schema<infer P> ? InnerInferType<P> : never; | ||
@@ -538,6 +481,6 @@ // Shut off automatic exporting after this statement | ||
type KeyOfUndefined<T> = { | ||
[P in keyof T]-?: undefined extends T[P] ? P : never | ||
[P in keyof T]-?: undefined extends T[P] ? P : never; | ||
}[keyof T]; | ||
type Id<T> = {[K in keyof T]: T[K]}; | ||
type Id<T> = { [K in keyof T]: T[K] }; | ||
type RequiredProps<T> = Pick<T, Exclude<keyof T, KeyOfUndefined<T>>>; | ||
@@ -544,0 +487,0 @@ type NotRequiredProps<T> = Partial<Pick<T, KeyOfUndefined<T>>>; |
{ | ||
"name": "@types/yup", | ||
"version": "0.26.22", | ||
"version": "0.26.23", | ||
"description": "TypeScript definitions for yup", | ||
@@ -61,2 +61,7 @@ "license": "MIT", | ||
"githubUsername": "mauricedb" | ||
}, | ||
{ | ||
"name": "Kalley Powell", | ||
"url": "https://github.com/kalley", | ||
"githubUsername": "kalley" | ||
} | ||
@@ -73,4 +78,4 @@ ], | ||
"dependencies": {}, | ||
"typesPublisherContentHash": "af336785518d245c39df946c7399dc6b7f1811f6d3b608df3e8ef9166a0199d3", | ||
"typeScriptVersion": "2.8" | ||
"typesPublisherContentHash": "5ee48019095c6520dc294726f8375399a2c276679687079b9b4e53da51426958", | ||
"typeScriptVersion": "3.1" | ||
} |
@@ -11,3 +11,3 @@ # Installation | ||
Additional Details | ||
* Last updated: Tue, 16 Jul 2019 16:22:25 GMT | ||
* Last updated: Tue, 20 Aug 2019 18:58:56 GMT | ||
* Dependencies: none | ||
@@ -17,2 +17,2 @@ * Global values: none | ||
# Credits | ||
These definitions were written by Dominik Hardtke <https://github.com/dhardtke>, Vladyslav Tserman <https://github.com/vtserman>, Moreton Bay Regional Council <https://github.com/MoretonBayRC>, Sindre Seppola <https://github.com/sseppola>, Yash Kulshrestha <https://github.com/YashdalfTheGray>, Vincent Pizzo <https://github.com/vincentjames501>, Robert Bullen <https://github.com/robertbullen>, Yusuke Sato <https://github.com/sat0yu>, Dan Rumney <https://github.com/dancrumb>, Desmond Koh <https://github.com/deskoh>, and Maurice de Beijer <https://github.com/mauricedb>. | ||
These definitions were written by Dominik Hardtke <https://github.com/dhardtke>, Vladyslav Tserman <https://github.com/vtserman>, Moreton Bay Regional Council <https://github.com/MoretonBayRC>, Sindre Seppola <https://github.com/sseppola>, Yash Kulshrestha <https://github.com/YashdalfTheGray>, Vincent Pizzo <https://github.com/vincentjames501>, Robert Bullen <https://github.com/robertbullen>, Yusuke Sato <https://github.com/sat0yu>, Dan Rumney <https://github.com/dancrumb>, Desmond Koh <https://github.com/deskoh>, Maurice de Beijer <https://github.com/mauricedb>, and Kalley Powell <https://github.com/kalley>. |
23121
410