# Class: MixedType

Mixed type supports any Object types, you can change the value to anything else you like, it can be represented in the following ways:

# Options

  • required flag to define if the field is mandatory
  • validator that will be applied to the field a validation function, validation object or string with the name of the custom validator
  • default that will define the initial value of the field, this option allows a value or a function
  • immutable that will define this field as immutable. Ottoman prevents you from changing immutable fields if the schema as configure like strict


const schema = new Schema({
  inline: Schema.Types.Mixed,
  types: { type: Schema.Types.Mixed, required: true },
  obj: Object,
  empty: {},

schema.fields.inline instanceof MixedType; // true
schema.fields.types instanceof MixedType;  // true
schema.fields.obj instanceof MixedType;    // true
schema.fields.empty instanceof MixedType;  // true

const data = {
 inline: { name: 'george' },
 types: {
   email: 'george@gmail.com',
 obj: 'Hello',
 empty: { hello: 'hello' },

const result = validate(data, schema);

// Output!!!
// {
//     "inline": {
//         "name": "george"
//     },
//     "types": {
//         "email": "george@gmail.com"
//     },
//     "obj": "Hello",
//     "empty": {
//         "hello": "hello"
//     }
// }

# Hierarchy



# Constructors

# constructor

+ new MixedType(name: string, options?: CoreTypeOptions): MixedType

Overrides CoreType.constructor


Name Type
name string
options? CoreTypeOptions

Returns: MixedType

# Properties

# name

name: string

Inherited from IOttomanType.name

# Optional options

options? : CoreTypeOptions

Inherited from CoreType.options

# typeName

typeName: string

Inherited from IOttomanType.typeName

# Static sName

sName: string = "Mixed"

Overrides CoreType.sName

# Accessors

# default

get default(): unknown

Inherited from CoreType.default

Returns: unknown

# required

get required(): boolean | RequiredOption | RequiredFunction

Inherited from CoreType.required

Returns: boolean | RequiredOption | RequiredFunction

# validator

get validator(): ValidatorOption | ValidatorFunction | string | undefined

Inherited from CoreType.validator

Returns: ValidatorOption | ValidatorFunction | string | undefined

# Methods

# buildDefault

buildDefault(): unknown

Inherited from CoreType.buildDefault

Returns: unknown

# cast

cast(value: unknown, strategy: any): unknown

Overrides IOttomanType.cast


Name Type
value unknown
strategy any

Returns: unknown

# checkRequired

checkRequired(): string | void

Inherited from CoreType.checkRequired

Returns: string | void

# checkValidator

checkValidator(value: unknown): void

Inherited from CoreType.checkValidator


Name Type
value unknown

Returns: void

# isEmpty

isEmpty(value: unknown): boolean

Inherited from CoreType.isEmpty


Name Type
value unknown

Returns: boolean

# isStrictStrategy

isStrictStrategy(strategy: VALIDATION_STRATEGY): boolean

Inherited from CoreType.isStrictStrategy


Name Type

Returns: boolean

# validate

validate(value: unknown, strict: boolean): unknown

Inherited from CoreType.validate

Overrides IOttomanType.validate


Name Type Default
value unknown -
strict boolean true

Returns: unknown