Skip to main content

Class: BaseSchema<TCast, TContext, TOutput>

yup.BaseSchema

Type parameters​

NameType
TCastany
TContextAnyObject
TOutputany

Hierarchy​

Constructors​

constructor​

• new BaseSchema<TCast, TContext, TOutput>(options?)

Type parameters​

NameType
TCastany
TContextAnyObject
TOutputany

Parameters​

NameType
options?SchemaOptions<any>

Properties​

__inputType​

• Readonly __inputType: TCast


__isYupSchema__​

• Readonly __isYupSchema__: boolean


__outputType​

• Readonly __outputType: TOutput


_blacklist​

• Protected _blacklist: default


_blacklistError​

• Private Optional _blacklistError: any


_mutate​

• Private Optional _mutate: any


_typeError​

• Private Optional _typeError: any


_whitelist​

• Protected _whitelist: default


_whitelistError​

• Private Optional _whitelistError: any


conditions​

• Private conditions: any


deps​

• Readonly deps: readonly string[]


equals​

• equals: <U>(enums: (default<unknown> | Maybe<U>)[], message?: Message<{ values: any }>) => BaseSchema<any, AnyObject, any>

Type declaration​

â–¸ <U>(enums, message?): BaseSchema<any, AnyObject, any>

Type parameters​
NameType
Uextends any
Parameters​
NameType
enums(default<unknown> | Maybe<U>)[]
message?Message<{ values: any }>
Returns​

BaseSchema<any, AnyObject, any>


exclusiveTests​

• Protected exclusiveTests: Record<string, boolean>


is​

• is: <U>(enums: (default<unknown> | Maybe<U>)[], message?: Message<{ values: any }>) => BaseSchema<any, AnyObject, any>

Type declaration​

â–¸ <U>(enums, message?): BaseSchema<any, AnyObject, any>

Type parameters​
NameType
Uextends any
Parameters​
NameType
enums(default<unknown> | Maybe<U>)[]
message?Message<{ values: any }>
Returns​

BaseSchema<any, AnyObject, any>


nope​

• nope: <U>(enums: (default<unknown> | Maybe<U>)[], message?: Message<{ values: any }>) => BaseSchema<any, AnyObject, any>

Type declaration​

â–¸ <U>(enums, message?): BaseSchema<any, AnyObject, any>

Type parameters​
NameType
Uextends any
Parameters​
NameType
enums(default<unknown> | Maybe<U>)[]
message?Message<{ values: any }>
Returns​

BaseSchema<any, AnyObject, any>


not​

• not: <U>(enums: (default<unknown> | Maybe<U>)[], message?: Message<{ values: any }>) => BaseSchema<any, AnyObject, any>

Type declaration​

â–¸ <U>(enums, message?): BaseSchema<any, AnyObject, any>

Type parameters​
NameType
Uextends any
Parameters​
NameType
enums(default<unknown> | Maybe<U>)[]
message?Message<{ values: any }>
Returns​

BaseSchema<any, AnyObject, any>


spec​

• spec: SchemaSpec<any>


tests​

• tests: Test[]


transforms​

• transforms: TransformFunction<AnySchema<any, any, any>>[]


type​

• Readonly type: string

Accessors​

_type​

• get _type(): string

Returns​

string

Methods​

_cast​

â–¸ Protected _cast(rawValue, _options): any

Parameters​

NameType
rawValueany
_optionsCastOptions<TContext>

Returns​

any


_getDefault​

â–¸ Protected _getDefault(): any

Returns​

any


_isPresent​

â–¸ Protected _isPresent(value): boolean

Parameters​

NameType
valueunknown

Returns​

boolean


_typeCheck​

â–¸ Protected _typeCheck(_value): _value is NonNullable<TCast>

Parameters​

NameType
_valueany

Returns​

_value is NonNullable<TCast>


_validate​

â–¸ Protected _validate(_value, options, cb): void

Parameters​

NameType
_valueany
optionsundefined | InternalOptions<TContext>
cbCallback<any>

Returns​

void


cast​

â–¸ cast(value, options?): TCast

Parameters​

NameType
valueany
options?CastOptions<TContext>

Returns​

TCast


clone​

â–¸ clone(spec?): BaseSchema<TCast, TContext, TOutput>

Parameters​

NameType
spec?Partial<SchemaSpec<any>>

Returns​

BaseSchema<TCast, TContext, TOutput>


concat​

â–¸ concat(schema): BaseSchema<TCast, TContext, TOutput>

Parameters​

NameType
schemaBaseSchema<TCast, TContext, TOutput>

Returns​

BaseSchema<TCast, TContext, TOutput>

â–¸ concat(schema): AnySchema<any, any, any>

Parameters​

NameType
schemaAnySchema<any, any, any>

Returns​

AnySchema<any, any, any>


default​

â–¸ default(def): any

Parameters​

NameType
defany

Returns​

any


defined​

â–¸ defined(message?): any

Parameters​

NameType
message?Message<{}>

Returns​

any


describe​

â–¸ describe(): SchemaDescription

Returns​

SchemaDescription


getDefault​

â–¸ getDefault(options?): TCast

Parameters​

NameType
options?ResolveOptions<any>

Returns​

TCast


isType​

â–¸ isType(v): boolean

Parameters​

NameType
vany

Returns​

boolean


isValid​

â–¸ isValid(value, options?): Promise<boolean>

Parameters​

NameType
valueany
options?ValidateOptions<TContext>

Returns​

Promise<boolean>


isValidSync​

â–¸ isValidSync(value, options?): value is TOutput

Parameters​

NameType
valueany
options?ValidateOptions<TContext>

Returns​

value is TOutput


label​

â–¸ label(label): BaseSchema<TCast, TContext, TOutput>

Parameters​

NameType
labelstring

Returns​

BaseSchema<TCast, TContext, TOutput>


meta​

â–¸ meta(): undefined | Record<string, unknown>

Returns​

undefined | Record<string, unknown>

â–¸ meta(obj): BaseSchema<TCast, TContext, TOutput>

Parameters​

NameType
objRecord<string, unknown>

Returns​

BaseSchema<TCast, TContext, TOutput>


notOneOf​

â–¸ notOneOf<U>(enums, message?): BaseSchema<TCast, TContext, TOutput>

Type parameters​

Name
U

Parameters​

NameType
enums(default<unknown> | Maybe<U>)[]
message?Message<{ values: any }>

Returns​

BaseSchema<TCast, TContext, TOutput>


notRequired​

â–¸ notRequired(): any

Returns​

any


nullable​

â–¸ nullable(isNullable?): any

Parameters​

NameType
isNullable?true

Returns​

any

â–¸ nullable(isNullable): any

Parameters​

NameType
isNullablefalse

Returns​

any


oneOf​

â–¸ oneOf<U>(enums, message?): BaseSchema<TCast, TContext, TOutput>

Type parameters​

Name
U

Parameters​

NameType
enums(default<unknown> | Maybe<U>)[]
message?Message<{ values: any }>

Returns​

BaseSchema<TCast, TContext, TOutput>


optional​

â–¸ optional(): any

Returns​

any


required​

â–¸ required(message?): any

Parameters​

NameType
message?Message<{}>

Returns​

any


resolve​

â–¸ resolve(options): BaseSchema<TCast, TContext, TOutput>

Parameters​

NameType
optionsResolveOptions<any>

Returns​

BaseSchema<TCast, TContext, TOutput>


strict​

â–¸ strict(isStrict?): BaseSchema<TCast, TContext, TOutput>

Parameters​

NameType
isStrict?boolean

Returns​

BaseSchema<TCast, TContext, TOutput>


strip​

â–¸ strip(strip?): BaseSchema<TCast, TContext, TOutput>

Parameters​

NameType
strip?boolean

Returns​

BaseSchema<TCast, TContext, TOutput>


test​

â–¸ test(options): BaseSchema<TCast, TContext, TOutput>

Adds a test function to the schema's queue of tests. tests can be exclusive or non-exclusive.

  • exclusive tests, will replace any existing tests of the same name.
  • non-exclusive: can be stacked

If a non-exclusive test is added to a schema with an exclusive test of the same name the exclusive test is removed and further tests of the same name will be stacked.

If an exclusive test is added to a schema with non-exclusive tests of the same name the previous tests are removed and further tests of the same name will replace each other.

Parameters​

NameType
optionsTestConfig<TCast, TContext>

Returns​

BaseSchema<TCast, TContext, TOutput>

â–¸ test(test): BaseSchema<TCast, TContext, TOutput>

Parameters​

NameType
testTestFunction<TCast, TContext>

Returns​

BaseSchema<TCast, TContext, TOutput>

â–¸ test(name, test): BaseSchema<TCast, TContext, TOutput>

Parameters​

NameType
namestring
testTestFunction<TCast, TContext>

Returns​

BaseSchema<TCast, TContext, TOutput>

â–¸ test(name, message, test): BaseSchema<TCast, TContext, TOutput>

Parameters​

NameType
namestring
messageMessage<{}>
testTestFunction<TCast, TContext>

Returns​

BaseSchema<TCast, TContext, TOutput>


transform​

â–¸ transform(fn): BaseSchema<TCast, TContext, TOutput>

Parameters​

NameType
fnTransformFunction<BaseSchema<TCast, TContext, TOutput>>

Returns​

BaseSchema<TCast, TContext, TOutput>


typeError​

â–¸ typeError(message): BaseSchema<TCast, TContext, TOutput>

Parameters​

NameType
messageMessage<{}>

Returns​

BaseSchema<TCast, TContext, TOutput>


validate​

â–¸ validate(value, options?): Promise<TOutput>

Parameters​

NameType
valueany
options?ValidateOptions<TContext>

Returns​

Promise<TOutput>


validateAt​

â–¸ validateAt(path, value, options?): Promise<TOutput>

Parameters​

NameType
pathstring
valueany
options?ValidateOptions<TContext>

Returns​

Promise<TOutput>


validateSync​

â–¸ validateSync(value, options?): TOutput

Parameters​

NameType
valueany
options?ValidateOptions<TContext>

Returns​

TOutput


validateSyncAt​

â–¸ validateSyncAt(path, value, options?): TOutput

Parameters​

NameType
pathstring
valueany
options?ValidateOptions<TContext>

Returns​

TOutput


when​

â–¸ when(options): BaseSchema<TCast, TContext, TOutput>

Parameters​

NameType
optionsConditionOptions<BaseSchema<TCast, TContext, TOutput>>

Returns​

BaseSchema<TCast, TContext, TOutput>

â–¸ when(keys, options): BaseSchema<TCast, TContext, TOutput>

Parameters​

NameType
keysstring | string[]
optionsConditionOptions<BaseSchema<TCast, TContext, TOutput>>

Returns​

BaseSchema<TCast, TContext, TOutput>


withMutation​

â–¸ withMutation<T>(fn): T

Type parameters​

Name
T

Parameters​

NameType
fn(schema: BaseSchema<TCast, TContext, TOutput>) => T

Returns​

T