Skip to main content

Class: ObjectSchema<TShape, TContext, TIn, TOut>

yup.ObjectSchema

Type parameters​

NameType
TShapeextends ObjectShape
TContextextends AnyObject = AnyObject
TInextends Maybe<TypeOfShape<TShape>> = TypeOfShape<TShape>
TOutextends Maybe<AssertsShape<TShape>> = AssertsShape<TShape> | Optionals<TIn>

Hierarchy​

  • BaseSchema<TIn, TContext, TOut>

    ↳ ObjectSchema

Constructors​

constructor​

• new ObjectSchema<TShape, TContext, TIn, TOut>(spec?)

Type parameters​

NameType
TShapeextends ObjectShape
TContextextends AnyObject = AnyObject
TInextends Maybe<TypeOfShape<TShape>> = TypeOfShape<TShape>
TOutextends Maybe<AssertsShape<TShape>> = AssertsShape<TShape> | Extract<TIn, undefined | null>

Parameters​

NameType
spec?TShape

Overrides​

BaseSchema.constructor

Properties​

__inputType​

• Readonly __inputType: TIn

Inherited from​

BaseSchema.__inputType


__isYupSchema__​

• Readonly __isYupSchema__: boolean

Inherited from​

BaseSchema.isYupSchema


__outputType​

• Readonly __outputType: TOut

Inherited from​

BaseSchema.__outputType


_blacklist​

• Protected _blacklist: default

Inherited from​

BaseSchema._blacklist


_excludedEdges​

• Private _excludedEdges: any


_nodes​

• Private _nodes: any


_sortErrors​

• Private _sortErrors: any


_whitelist​

• Protected _whitelist: default

Inherited from​

BaseSchema._whitelist


deps​

• Readonly deps: readonly string[]

Inherited from​

BaseSchema.deps


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>

Inherited from​

BaseSchema.equals


exclusiveTests​

• Protected exclusiveTests: Record<string, boolean>

Inherited from​

BaseSchema.exclusiveTests


fields​

• fields: TShape


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>

Inherited from​

BaseSchema.is


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>

Inherited from​

BaseSchema.nope


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>

Inherited from​

BaseSchema.not


spec​

• spec: ObjectSchemaSpec

Overrides​

BaseSchema.spec


tests​

• tests: Test[]

Inherited from​

BaseSchema.tests


transforms​

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

Inherited from​

BaseSchema.transforms


type​

• Readonly type: string

Inherited from​

BaseSchema.type

Accessors​

_type​

• get _type(): string

Returns​

string

Inherited from​

BaseSchema._type

Methods​

_cast​

â–¸ Protected _cast(_value, options?): any

Parameters​

NameType
_valueany
options?InternalOptions<TContext>

Returns​

any

Overrides​

BaseSchema._cast


_getDefault​

â–¸ Protected _getDefault(): any

Returns​

any

Overrides​

BaseSchema._getDefault


_isPresent​

â–¸ Protected _isPresent(value): boolean

Parameters​

NameType
valueunknown

Returns​

boolean

Inherited from​

BaseSchema._isPresent


_typeCheck​

â–¸ Protected _typeCheck(value): value is NonNullable<TIn>

Parameters​

NameType
valueany

Returns​

value is NonNullable<TIn>

Overrides​

BaseSchema._typeCheck


_validate​

â–¸ Protected _validate(_value, opts, callback): void

Parameters​

NameType
_valueany
optsundefined | InternalOptions<TContext>
callbackCallback<any>

Returns​

void

Overrides​

BaseSchema._validate


camelCase​

â–¸ camelCase(): ObjectSchema<TShape, TContext, TIn, TOut>

Returns​

ObjectSchema<TShape, TContext, TIn, TOut>


cast​

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

Parameters​

NameType
valueany
options?CastOptions<TContext>

Returns​

TIn

Inherited from​

BaseSchema.cast


clone​

â–¸ clone(spec?): ObjectSchema<TShape, TContext, TIn, TOut>

Parameters​

NameType
spec?ObjectSchemaSpec

Returns​

ObjectSchema<TShape, TContext, TIn, TOut>

Overrides​

BaseSchema.clone


concat​

â–¸ concat<TOther>(schema): TOther extends ObjectSchema<S, C, IType, AssertsShape<S> | Extract<IType, undefined | null>> ? ObjectSchema<TShape & S, TContext & C, Extract<IType, undefined | null> | TypeOfShape<TShape & S>, AssertsShape<TShape & S> | Extract<Extract<IType, undefined | null>, undefined | null> | Extract<TypeOfShape<TShape & S>, undefined | null>> : never

Type parameters​

NameType
TOtherextends ObjectSchema<any, any, any, any, TOther>

Parameters​

NameType
schemaTOther

Returns​

TOther extends ObjectSchema<S, C, IType, AssertsShape<S> | Extract<IType, undefined | null>> ? ObjectSchema<TShape & S, TContext & C, Extract<IType, undefined | null> | TypeOfShape<TShape & S>, AssertsShape<TShape & S> | Extract<Extract<IType, undefined | null>, undefined | null> | Extract<TypeOfShape<TShape & S>, undefined | null>> : never

Overrides​

BaseSchema.concat

â–¸ concat(schema): ObjectSchema<TShape, TContext, TIn, TOut>

Parameters​

NameType
schemaObjectSchema<TShape, TContext, TIn, TOut>

Returns​

ObjectSchema<TShape, TContext, TIn, TOut>

Overrides​

BaseSchema.concat


constantCase​

â–¸ constantCase(): ObjectSchema<TShape, TContext, TIn, TOut>

Returns​

ObjectSchema<TShape, TContext, TIn, TOut>


default​

â–¸ default(def): any

Parameters​

NameType
defany

Returns​

any

Inherited from​

BaseSchema.default


defined​

â–¸ defined(message?): any

Parameters​

NameType
message?Message<{}>

Returns​

any

Inherited from​

BaseSchema.defined


describe​

â–¸ describe(): SchemaObjectDescription

Returns​

SchemaObjectDescription

Overrides​

BaseSchema.describe


from​

â–¸ from(from, to, alias?): ObjectSchema<TShape, TContext, TIn, TOut>

Parameters​

NameType
fromstring
tokeyof TShape
alias?boolean

Returns​

ObjectSchema<TShape, TContext, TIn, TOut>


getDefault​

â–¸ getDefault(options?): TIn

Parameters​

NameType
options?ResolveOptions<any>

Returns​

TIn

Inherited from​

BaseSchema.getDefault


getDefaultFromShape​

â–¸ getDefaultFromShape(): DefaultFromShape<TShape>

Returns​

DefaultFromShape<TShape>


isType​

â–¸ isType(v): boolean

Parameters​

NameType
vany

Returns​

boolean

Inherited from​

BaseSchema.isType


isValid​

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

Parameters​

NameType
valueany
options?ValidateOptions<TContext>

Returns​

Promise<boolean>

Inherited from​

BaseSchema.isValid


isValidSync​

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

Parameters​

NameType
valueany
options?ValidateOptions<TContext>

Returns​

value is TOut

Inherited from​

BaseSchema.isValidSync


label​

â–¸ label(label): ObjectSchema<TShape, TContext, TIn, TOut>

Parameters​

NameType
labelstring

Returns​

ObjectSchema<TShape, TContext, TIn, TOut>

Inherited from​

BaseSchema.label


meta​

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

Returns​

undefined | Record<string, unknown>

Inherited from​

BaseSchema.meta

â–¸ meta(obj): ObjectSchema<TShape, TContext, TIn, TOut>

Parameters​

NameType
objRecord<string, unknown>

Returns​

ObjectSchema<TShape, TContext, TIn, TOut>

Inherited from​

BaseSchema.meta


noUnknown​

â–¸ noUnknown(noAllow?, message?): ObjectSchema<TShape, TContext, TIn, TOut>

Parameters​

NameType
noAllow?boolean
message?Message<{}>

Returns​

ObjectSchema<TShape, TContext, TIn, TOut>


notOneOf​

â–¸ notOneOf<U>(enums, message?): ObjectSchema<TShape, TContext, TIn, TOut>

Type parameters​

NameType
Uextends Maybe<TypeOfShape<TShape>>

Parameters​

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

Returns​

ObjectSchema<TShape, TContext, TIn, TOut>

Inherited from​

BaseSchema.notOneOf


notRequired​

â–¸ notRequired(): any

Returns​

any

Inherited from​

BaseSchema.notRequired


nullable​

â–¸ nullable(isNullable?): any

Parameters​

NameType
isNullable?true

Returns​

any

Inherited from​

BaseSchema.nullable

â–¸ nullable(isNullable): any

Parameters​

NameType
isNullablefalse

Returns​

any

Inherited from​

BaseSchema.nullable


omit​

â–¸ omit(keys): any

Parameters​

NameType
keysstring[]

Returns​

any


oneOf​

â–¸ oneOf<U>(enums, message?): ObjectSchema<TShape, TContext, TIn, TOut>

Type parameters​

NameType
Uextends Maybe<TypeOfShape<TShape>>

Parameters​

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

Returns​

ObjectSchema<TShape, TContext, TIn, TOut>

Inherited from​

BaseSchema.oneOf


optional​

â–¸ optional(): any

Returns​

any

Inherited from​

BaseSchema.optional


pick​

â–¸ pick(keys): any

Parameters​

NameType
keysstring[]

Returns​

any


required​

â–¸ required(message?): any

Parameters​

NameType
message?Message<{}>

Returns​

any

Inherited from​

BaseSchema.required


resolve​

â–¸ resolve(options): ObjectSchema<TShape, TContext, TIn, TOut>

Parameters​

NameType
optionsResolveOptions<any>

Returns​

ObjectSchema<TShape, TContext, TIn, TOut>

Inherited from​

BaseSchema.resolve


shape​

â–¸ shape<TNextShape>(additions, excludes?): ObjectSchema<Assign<TShape, TNextShape>, TContext, Extract<TIn, undefined | null> | TypeOfShape<Assign<TShape, TNextShape>>, AssertsShape<Assign<TShape, TNextShape>> | Extract<Extract<TIn, undefined | null>, undefined | null> | Extract<TypeOfShape<Assign<TShape, TNextShape>>, undefined | null>>

Type parameters​

NameType
TNextShapeextends ObjectShape

Parameters​

NameType
additionsTNextShape
excludes?[string, string][]

Returns​

ObjectSchema<Assign<TShape, TNextShape>, TContext, Extract<TIn, undefined | null> | TypeOfShape<Assign<TShape, TNextShape>>, AssertsShape<Assign<TShape, TNextShape>> | Extract<Extract<TIn, undefined | null>, undefined | null> | Extract<TypeOfShape<Assign<TShape, TNextShape>>, undefined | null>>


snakeCase​

â–¸ snakeCase(): ObjectSchema<TShape, TContext, TIn, TOut>

Returns​

ObjectSchema<TShape, TContext, TIn, TOut>


strict​

â–¸ strict(isStrict?): ObjectSchema<TShape, TContext, TIn, TOut>

Parameters​

NameType
isStrict?boolean

Returns​

ObjectSchema<TShape, TContext, TIn, TOut>

Inherited from​

BaseSchema.strict


strip​

â–¸ strip(strip?): ObjectSchema<TShape, TContext, TIn, TOut>

Parameters​

NameType
strip?boolean

Returns​

ObjectSchema<TShape, TContext, TIn, TOut>

Inherited from​

BaseSchema.strip


test​

â–¸ test(options): ObjectSchema<TShape, TContext, TIn, TOut>

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<TIn, TContext>

Returns​

ObjectSchema<TShape, TContext, TIn, TOut>

Inherited from​

BaseSchema.test

â–¸ test(test): ObjectSchema<TShape, TContext, TIn, TOut>

Parameters​

NameType
testTestFunction<TIn, TContext>

Returns​

ObjectSchema<TShape, TContext, TIn, TOut>

Inherited from​

BaseSchema.test

â–¸ test(name, test): ObjectSchema<TShape, TContext, TIn, TOut>

Parameters​

NameType
namestring
testTestFunction<TIn, TContext>

Returns​

ObjectSchema<TShape, TContext, TIn, TOut>

Inherited from​

BaseSchema.test

â–¸ test(name, message, test): ObjectSchema<TShape, TContext, TIn, TOut>

Parameters​

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

Returns​

ObjectSchema<TShape, TContext, TIn, TOut>

Inherited from​

BaseSchema.test


transform​

â–¸ transform(fn): ObjectSchema<TShape, TContext, TIn, TOut>

Parameters​

NameType
fnTransformFunction<ObjectSchema<TShape, TContext, TIn, TOut>>

Returns​

ObjectSchema<TShape, TContext, TIn, TOut>

Inherited from​

BaseSchema.transform


transformKeys​

â–¸ transformKeys(fn): ObjectSchema<TShape, TContext, TIn, TOut>

Parameters​

NameType
fn(key: string) => string

Returns​

ObjectSchema<TShape, TContext, TIn, TOut>


typeError​

â–¸ typeError(message): ObjectSchema<TShape, TContext, TIn, TOut>

Parameters​

NameType
messageMessage<{}>

Returns​

ObjectSchema<TShape, TContext, TIn, TOut>

Inherited from​

BaseSchema.typeError


unknown​

â–¸ unknown(allow?, message?): ObjectSchema<TShape, TContext, TIn, TOut>

Parameters​

NameType
allow?boolean
message?Message<{}>

Returns​

ObjectSchema<TShape, TContext, TIn, TOut>


validate​

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

Parameters​

NameType
valueany
options?ValidateOptions<TContext>

Returns​

Promise<TOut>

Inherited from​

BaseSchema.validate


validateAt​

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

Parameters​

NameType
pathstring
valueany
options?ValidateOptions<TContext>

Returns​

Promise<TOut>

Inherited from​

BaseSchema.validateAt


validateSync​

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

Parameters​

NameType
valueany
options?ValidateOptions<TContext>

Returns​

TOut

Inherited from​

BaseSchema.validateSync


validateSyncAt​

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

Parameters​

NameType
pathstring
valueany
options?ValidateOptions<TContext>

Returns​

TOut

Inherited from​

BaseSchema.validateSyncAt


when​

â–¸ when(options): ObjectSchema<TShape, TContext, TIn, TOut>

Parameters​

NameType
optionsConditionOptions<ObjectSchema<TShape, TContext, TIn, TOut>>

Returns​

ObjectSchema<TShape, TContext, TIn, TOut>

Inherited from​

BaseSchema.when

â–¸ when(keys, options): ObjectSchema<TShape, TContext, TIn, TOut>

Parameters​

NameType
keysstring | string[]
optionsConditionOptions<ObjectSchema<TShape, TContext, TIn, TOut>>

Returns​

ObjectSchema<TShape, TContext, TIn, TOut>

Inherited from​

BaseSchema.when


withMutation​

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

Type parameters​

Name
T

Parameters​

NameType
fn(schema: ObjectSchema<TShape, TContext, TIn, TOut>) => T

Returns​

T

Inherited from​

BaseSchema.withMutation