# 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

example

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);
console.log(result);

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

# Hierarchy

CoreType

MixedType

# Constructors

# constructor

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

Overrides CoreType.constructor

Parameters:

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

Parameters:

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

Parameters:

Name Type
value unknown

Returns: void


# isEmpty

isEmpty(value: unknown): boolean

Inherited from CoreType.isEmpty

Parameters:

Name Type
value unknown

Returns: boolean


# isStrictStrategy

isStrictStrategy(strategy: VALIDATION_STRATEGY): boolean

Inherited from CoreType.isStrictStrategy

Parameters:

Name Type
strategy VALIDATION_STRATEGY

Returns: boolean


# validate

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

Inherited from CoreType.validate

Overrides IOttomanType.validate

Parameters:

Name Type Default
value unknown -
strict boolean true

Returns: unknown