Class: ObjectSchema<TShape, TContext, TIn, TOut>
yup.ObjectSchema
Type parameters​
Name | Type |
---|---|
TShape | extends ObjectShape |
TContext | extends AnyObject = AnyObject |
TIn | extends Maybe <TypeOfShape <TShape >> = TypeOfShape <TShape > |
TOut | extends Maybe <AssertsShape <TShape >> = AssertsShape <TShape > | Optionals <TIn > |
Hierarchy​
BaseSchema
<TIn
,TContext
,TOut
>↳
ObjectSchema
Constructors​
constructor​
• new ObjectSchema<TShape
, TContext
, TIn
, TOut
>(spec?
)
Type parameters​
Name | Type |
---|---|
TShape | extends ObjectShape |
TContext | extends AnyObject = AnyObject |
TIn | extends Maybe <TypeOfShape <TShape >> = TypeOfShape <TShape > |
TOut | extends Maybe <AssertsShape <TShape >> = AssertsShape <TShape > | Extract <TIn , undefined | null > |
Parameters​
Name | Type |
---|---|
spec? | TShape |
Overrides​
Properties​
__inputType​
• Readonly
__inputType: TIn
Inherited from​
__isYupSchema__​
• Readonly
__isYupSchema__: boolean
Inherited from​
__outputType​
• Readonly
__outputType: TOut
Inherited from​
_blacklist​
• Protected
_blacklist: default
Inherited from​
_excludedEdges​
• Private
_excludedEdges: any
_nodes​
• Private
_nodes: any
_sortErrors​
• Private
_sortErrors: any
_whitelist​
• Protected
_whitelist: default
Inherited from​
deps​
• Readonly
deps: readonly string
[]
Inherited from​
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​
Name | Type |
---|---|
U | extends any |
Parameters​
Name | Type |
---|---|
enums | (default <unknown > | Maybe <U >)[] |
message? | Message <{ values : any }> |
Returns​
BaseSchema
<any
, AnyObject
, any
>
Inherited from​
exclusiveTests​
• Protected
exclusiveTests: Record
<string
, boolean
>
Inherited from​
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​
Name | Type |
---|---|
U | extends any |
Parameters​
Name | Type |
---|---|
enums | (default <unknown > | Maybe <U >)[] |
message? | Message <{ values : any }> |
Returns​
BaseSchema
<any
, AnyObject
, any
>
Inherited from​
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​
Name | Type |
---|---|
U | extends any |
Parameters​
Name | Type |
---|---|
enums | (default <unknown > | Maybe <U >)[] |
message? | Message <{ values : any }> |
Returns​
BaseSchema
<any
, AnyObject
, any
>
Inherited from​
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​
Name | Type |
---|---|
U | extends any |
Parameters​
Name | Type |
---|---|
enums | (default <unknown > | Maybe <U >)[] |
message? | Message <{ values : any }> |
Returns​
BaseSchema
<any
, AnyObject
, any
>
Inherited from​
spec​
• spec: ObjectSchemaSpec
Overrides​
tests​
• tests: Test
[]
Inherited from​
transforms​
• transforms: TransformFunction
<AnySchema
<any
, any
, any
>>[]
Inherited from​
type​
• Readonly
type: string
Inherited from​
Accessors​
_type​
• get
_type(): string
Returns​
string
Inherited from​
BaseSchema._type
Methods​
_cast​
â–¸ Protected
_cast(_value
, options?
): any
Parameters​
Name | Type |
---|---|
_value | any |
options? | InternalOptions <TContext > |
Returns​
any
Overrides​
_getDefault​
â–¸ Protected
_getDefault(): any
Returns​
any
Overrides​
_isPresent​
â–¸ Protected
_isPresent(value
): boolean
Parameters​
Name | Type |
---|---|
value | unknown |
Returns​
boolean
Inherited from​
_typeCheck​
â–¸ Protected
_typeCheck(value
): value is NonNullable<TIn>
Parameters​
Name | Type |
---|---|
value | any |
Returns​
value is NonNullable<TIn>
Overrides​
_validate​
â–¸ Protected
_validate(_value
, opts
, callback
): void
Parameters​
Name | Type |
---|---|
_value | any |
opts | undefined | InternalOptions <TContext > |
callback | Callback <any > |
Returns​
void
Overrides​
camelCase​
â–¸ camelCase(): ObjectSchema
<TShape
, TContext
, TIn
, TOut
>
Returns​
ObjectSchema
<TShape
, TContext
, TIn
, TOut
>
cast​
â–¸ cast(value
, options?
): TIn
Parameters​
Name | Type |
---|---|
value | any |
options? | CastOptions <TContext > |
Returns​
TIn
Inherited from​
clone​
â–¸ clone(spec?
): ObjectSchema
<TShape
, TContext
, TIn
, TOut
>
Parameters​
Name | Type |
---|---|
spec? | ObjectSchemaSpec |
Returns​
ObjectSchema
<TShape
, TContext
, TIn
, TOut
>
Overrides​
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​
Name | Type |
---|---|
TOther | extends ObjectSchema <any , any , any , any , TOther > |
Parameters​
Name | Type |
---|---|
schema | TOther |
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​
â–¸ concat(schema
): ObjectSchema
<TShape
, TContext
, TIn
, TOut
>
Parameters​
Name | Type |
---|---|
schema | ObjectSchema <TShape , TContext , TIn , TOut > |
Returns​
ObjectSchema
<TShape
, TContext
, TIn
, TOut
>
Overrides​
constantCase​
â–¸ constantCase(): ObjectSchema
<TShape
, TContext
, TIn
, TOut
>
Returns​
ObjectSchema
<TShape
, TContext
, TIn
, TOut
>
default​
â–¸ default(def
): any
Parameters​
Name | Type |
---|---|
def | any |
Returns​
any
Inherited from​
defined​
â–¸ defined(message?
): any
Parameters​
Name | Type |
---|---|
message? | Message <{}> |
Returns​
any
Inherited from​
describe​
â–¸ describe(): SchemaObjectDescription
Returns​
SchemaObjectDescription
Overrides​
from​
â–¸ from(from
, to
, alias?
): ObjectSchema
<TShape
, TContext
, TIn
, TOut
>
Parameters​
Name | Type |
---|---|
from | string |
to | keyof TShape |
alias? | boolean |
Returns​
ObjectSchema
<TShape
, TContext
, TIn
, TOut
>
getDefault​
â–¸ getDefault(options?
): TIn
Parameters​
Name | Type |
---|---|
options? | ResolveOptions <any > |
Returns​
TIn
Inherited from​
getDefaultFromShape​
â–¸ getDefaultFromShape(): DefaultFromShape
<TShape
>
Returns​
DefaultFromShape
<TShape
>
isType​
â–¸ isType(v
): boolean
Parameters​
Name | Type |
---|---|
v | any |
Returns​
boolean
Inherited from​
isValid​
â–¸ isValid(value
, options?
): Promise
<boolean
>
Parameters​
Name | Type |
---|---|
value | any |
options? | ValidateOptions <TContext > |
Returns​
Promise
<boolean
>
Inherited from​
isValidSync​
â–¸ isValidSync(value
, options?
): value is TOut
Parameters​
Name | Type |
---|---|
value | any |
options? | ValidateOptions <TContext > |
Returns​
value is TOut
Inherited from​
label​
â–¸ label(label
): ObjectSchema
<TShape
, TContext
, TIn
, TOut
>
Parameters​
Name | Type |
---|---|
label | string |
Returns​
ObjectSchema
<TShape
, TContext
, TIn
, TOut
>
Inherited from​
meta​
â–¸ meta(): undefined
| Record
<string
, unknown
>
Returns​
undefined
| Record
<string
, unknown
>
Inherited from​
â–¸ meta(obj
): ObjectSchema
<TShape
, TContext
, TIn
, TOut
>
Parameters​
Name | Type |
---|---|
obj | Record <string , unknown > |
Returns​
ObjectSchema
<TShape
, TContext
, TIn
, TOut
>
Inherited from​
noUnknown​
â–¸ noUnknown(noAllow?
, message?
): ObjectSchema
<TShape
, TContext
, TIn
, TOut
>
Parameters​
Name | Type |
---|---|
noAllow? | boolean |
message? | Message <{}> |
Returns​
ObjectSchema
<TShape
, TContext
, TIn
, TOut
>
notOneOf​
â–¸ notOneOf<U
>(enums
, message?
): ObjectSchema
<TShape
, TContext
, TIn
, TOut
>
Type parameters​
Name | Type |
---|---|
U | extends Maybe <TypeOfShape <TShape >> |
Parameters​
Name | Type |
---|---|
enums | (default <unknown > | Maybe <U >)[] |
message? | Message <{ values : any }> |
Returns​
ObjectSchema
<TShape
, TContext
, TIn
, TOut
>
Inherited from​
notRequired​
â–¸ notRequired(): any
Returns​
any
Inherited from​
nullable​
â–¸ nullable(isNullable?
): any
Parameters​
Name | Type |
---|---|
isNullable? | true |
Returns​
any
Inherited from​
â–¸ nullable(isNullable
): any
Parameters​
Name | Type |
---|---|
isNullable | false |
Returns​
any
Inherited from​
omit​
â–¸ omit(keys
): any
Parameters​
Name | Type |
---|---|
keys | string [] |
Returns​
any
oneOf​
â–¸ oneOf<U
>(enums
, message?
): ObjectSchema
<TShape
, TContext
, TIn
, TOut
>
Type parameters​
Name | Type |
---|---|
U | extends Maybe <TypeOfShape <TShape >> |
Parameters​
Name | Type |
---|---|
enums | (default <unknown > | Maybe <U >)[] |
message? | Message <{ values : any }> |
Returns​
ObjectSchema
<TShape
, TContext
, TIn
, TOut
>
Inherited from​
optional​
â–¸ optional(): any
Returns​
any
Inherited from​
pick​
â–¸ pick(keys
): any
Parameters​
Name | Type |
---|---|
keys | string [] |
Returns​
any
required​
â–¸ required(message?
): any
Parameters​
Name | Type |
---|---|
message? | Message <{}> |
Returns​
any
Inherited from​
resolve​
â–¸ resolve(options
): ObjectSchema
<TShape
, TContext
, TIn
, TOut
>
Parameters​
Name | Type |
---|---|
options | ResolveOptions <any > |
Returns​
ObjectSchema
<TShape
, TContext
, TIn
, TOut
>
Inherited from​
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​
Name | Type |
---|---|
TNextShape | extends ObjectShape |
Parameters​
Name | Type |
---|---|
additions | TNextShape |
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​
Name | Type |
---|---|
isStrict? | boolean |
Returns​
ObjectSchema
<TShape
, TContext
, TIn
, TOut
>
Inherited from​
strip​
â–¸ strip(strip?
): ObjectSchema
<TShape
, TContext
, TIn
, TOut
>
Parameters​
Name | Type |
---|---|
strip? | boolean |
Returns​
ObjectSchema
<TShape
, TContext
, TIn
, TOut
>
Inherited from​
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​
Name | Type |
---|---|
options | TestConfig <TIn , TContext > |
Returns​
ObjectSchema
<TShape
, TContext
, TIn
, TOut
>
Inherited from​
â–¸ test(test
): ObjectSchema
<TShape
, TContext
, TIn
, TOut
>
Parameters​
Name | Type |
---|---|
test | TestFunction <TIn , TContext > |
Returns​
ObjectSchema
<TShape
, TContext
, TIn
, TOut
>
Inherited from​
â–¸ test(name
, test
): ObjectSchema
<TShape
, TContext
, TIn
, TOut
>
Parameters​
Name | Type |
---|---|
name | string |
test | TestFunction <TIn , TContext > |
Returns​
ObjectSchema
<TShape
, TContext
, TIn
, TOut
>
Inherited from​
â–¸ test(name
, message
, test
): ObjectSchema
<TShape
, TContext
, TIn
, TOut
>
Parameters​
Name | Type |
---|---|
name | string |
message | Message <{}> |
test | TestFunction <TIn , TContext > |
Returns​
ObjectSchema
<TShape
, TContext
, TIn
, TOut
>
Inherited from​
transform​
â–¸ transform(fn
): ObjectSchema
<TShape
, TContext
, TIn
, TOut
>
Parameters​
Name | Type |
---|---|
fn | TransformFunction <ObjectSchema <TShape , TContext , TIn , TOut >> |
Returns​
ObjectSchema
<TShape
, TContext
, TIn
, TOut
>
Inherited from​
transformKeys​
â–¸ transformKeys(fn
): ObjectSchema
<TShape
, TContext
, TIn
, TOut
>
Parameters​
Name | Type |
---|---|
fn | (key : string ) => string |
Returns​
ObjectSchema
<TShape
, TContext
, TIn
, TOut
>
typeError​
â–¸ typeError(message
): ObjectSchema
<TShape
, TContext
, TIn
, TOut
>
Parameters​
Name | Type |
---|---|
message | Message <{}> |
Returns​
ObjectSchema
<TShape
, TContext
, TIn
, TOut
>
Inherited from​
unknown​
â–¸ unknown(allow?
, message?
): ObjectSchema
<TShape
, TContext
, TIn
, TOut
>
Parameters​
Name | Type |
---|---|
allow? | boolean |
message? | Message <{}> |
Returns​
ObjectSchema
<TShape
, TContext
, TIn
, TOut
>
validate​
â–¸ validate(value
, options?
): Promise
<TOut
>
Parameters​
Name | Type |
---|---|
value | any |
options? | ValidateOptions <TContext > |
Returns​
Promise
<TOut
>
Inherited from​
validateAt​
â–¸ validateAt(path
, value
, options?
): Promise
<TOut
>
Parameters​
Name | Type |
---|---|
path | string |
value | any |
options? | ValidateOptions <TContext > |
Returns​
Promise
<TOut
>
Inherited from​
validateSync​
â–¸ validateSync(value
, options?
): TOut
Parameters​
Name | Type |
---|---|
value | any |
options? | ValidateOptions <TContext > |
Returns​
TOut
Inherited from​
validateSyncAt​
â–¸ validateSyncAt(path
, value
, options?
): TOut
Parameters​
Name | Type |
---|---|
path | string |
value | any |
options? | ValidateOptions <TContext > |
Returns​
TOut
Inherited from​
when​
â–¸ when(options
): ObjectSchema
<TShape
, TContext
, TIn
, TOut
>
Parameters​
Name | Type |
---|---|
options | ConditionOptions <ObjectSchema <TShape , TContext , TIn , TOut >> |
Returns​
ObjectSchema
<TShape
, TContext
, TIn
, TOut
>
Inherited from​
â–¸ when(keys
, options
): ObjectSchema
<TShape
, TContext
, TIn
, TOut
>
Parameters​
Name | Type |
---|---|
keys | string | string [] |
options | ConditionOptions <ObjectSchema <TShape , TContext , TIn , TOut >> |
Returns​
ObjectSchema
<TShape
, TContext
, TIn
, TOut
>
Inherited from​
withMutation​
â–¸ withMutation<T
>(fn
): T
Type parameters​
Name |
---|
T |
Parameters​
Name | Type |
---|---|
fn | (schema : ObjectSchema <TShape , TContext , TIn , TOut >) => T |
Returns​
T