Variable typesConst

types: {
    array: (<T>(itemType: T) => ArrayType<T[]>);
    arraySet: (<T>(valueType: T) => ModelType<ArraySet<TypeToData<T>>>);
    boolean: IdentityType<boolean>;
    dataModelData: (<M, K>(modelClass: _ClassOrObject<M, K>) => IdentityType<ModelUntransformedData<K extends M
        ? M extends AnyDataModel
            ? M
            : never
        : K extends AnyDataModel
            ? K
            : never> | ModelData<K extends M
        ? M extends AnyDataModel
            ? M
            : never
        : K extends AnyDataModel
            ? K
            : never>>);
    dateString: IdentityType<string>;
    dateTimestamp: IdentityType<number>;
    enum: (<E>(enumObject: E) => IdentityType<EnumValues<E>>);
    frozen: (<T>(dataType: T) => ModelType<Frozen<TypeToData<T>>>);
    integer: IdentityType<number>;
    literal: (<T>(literal: T) => IdentityType<T>);
    maybe: (<T>(baseType: T) => T | IdentityType<undefined>);
    maybeNull: (<T>(type: T) => T | IdentityType<null>);
    model: (<M, K>(modelClass: _ClassOrObject<M, K>) => ModelType<K>);
    nonEmptyString: IdentityType<string>;
    null: IdentityType<null>;
    number: IdentityType<number>;
    object: (<T>(objectFunction: T) => T);
    objectMap: (<T>(valueType: T) => ModelType<ObjectMap<TypeToData<T>>>);
    or: {
        <T>(dispatcher: ((sn: any) => T[number]), ...orTypes: T): T[number];
        <T>(...orTypes: T): T[number];
    };
    record: (<T>(valueType: T) => RecordType<T>);
    ref: (<O>(refConstructor: RefConstructor<O>) => ModelType<Ref<O>>);
    refinement: (<T>(baseType: T, checkFn: ((data: TypeToData<T>) => null | boolean | TypeCheckError), typeName?: string) => T);
    string: IdentityType<string>;
    tag: (<T, A>(baseType: T, tag: A, typeName?: string) => T);
    tuple: (<T>(...itemTypes: T) => ArrayType<T>);
    unchecked: (<T>() => IdentityType<T>);
    undefined: IdentityType<undefined>;
    mapArray<T>(valueType: T): ArrayType<ArrayType<[IdentityType<string>, T]>[]>;
    mapObject<T>(valueType: T): RecordType<T>;
    setArray<T>(valueType: T): ArrayType<T[]>;
} = ...

Type declaration

  • array: (<T>(itemType: T) => ArrayType<T[]>)
      • <T>(itemType): ArrayType<T[]>
      • A type that represents an array of values of a given type.

        Example:

        const numberArrayType = types.array(types.number)
        

        Type Parameters

        Parameters

        • itemType: T

          Type of inner items.

        Returns ArrayType<T[]>

        T Item type.

  • arraySet: (<T>(valueType: T) => ModelType<ArraySet<TypeToData<T>>>)
  • boolean: IdentityType<boolean>
  • dataModelData: (<M, K>(modelClass: _ClassOrObject<M, K>) => IdentityType<ModelUntransformedData<K extends M
        ? M extends AnyDataModel
            ? M
            : never
        : K extends AnyDataModel
            ? K
            : never> | ModelData<K extends M
        ? M extends AnyDataModel
            ? M
            : never
        : K extends AnyDataModel
            ? K
            : never>>)
      • <M, K>(modelClass): IdentityType<ModelUntransformedData<K extends M
            ? M extends AnyDataModel
                ? M
                : never
            : K extends AnyDataModel
                ? K
                : never> | ModelData<K extends M
            ? M extends AnyDataModel
                ? M
                : never
            : K extends AnyDataModel
                ? K
                : never>>
      • A type that represents a data model data. The type referenced in the model decorator will be used for type checking.

        Example:

        const someDataModelDataType = types.dataModelData(SomeModel)
        // or for recursive models
        const someDataModelDataType = types.dataModelData<SomeModel>(() => SomeModel)

        Type Parameters

        • M = never
        • K = M

        Parameters

        • modelClass: _ClassOrObject<M, K>

          Model class.

        Returns IdentityType<ModelUntransformedData<K extends M
            ? M extends AnyDataModel
                ? M
                : never
            : K extends AnyDataModel
                ? K
                : never> | ModelData<K extends M
            ? M extends AnyDataModel
                ? M
                : never
            : K extends AnyDataModel
                ? K
                : never>>

        M Data model type.

  • dateString: IdentityType<string>
  • dateTimestamp: IdentityType<number>
  • enum: (<E>(enumObject: E) => IdentityType<EnumValues<E>>)
      • <E>(enumObject): IdentityType<EnumValues<E>>
      • An enum type, based on a TypeScript alike enum object. Syntactic sugar for types.or(...enum_values.map(types.literal))

        Example:

        enum Color {
        Red = "red",
        Green = "green"
        }

        const colorType = types.enum(Color)

        Type Parameters

        • E extends EnumLike

        Parameters

        • enumObject: E

        Returns IdentityType<EnumValues<E>>

        E Enum type.

  • frozen: (<T>(dataType: T) => ModelType<Frozen<TypeToData<T>>>)
      • <T>(dataType): ModelType<Frozen<TypeToData<T>>>
      • A type that represents frozen data.

        Example:

        const frozenNumberType = types.frozen(types.number)
        const frozenAnyType = types.frozen(types.unchecked<any>())
        const frozenNumberArrayType = types.frozen(types.array(types.number))
        const frozenUncheckedNumberArrayType = types.frozen(types.unchecked<number[]>())

        Type Parameters

        Parameters

        • dataType: T

          Type of the frozen data.

        Returns ModelType<Frozen<TypeToData<T>>>

        T Type.

  • integer: IdentityType<number>
  • literal: (<T>(literal: T) => IdentityType<T>)
      • <T>(literal): IdentityType<T>
      • A type that represents a certain value of a primitive (for example an exact number or string).

        Example

        const hiType = types.literal("hi") // the string with value "hi"
        const number5Type = types.literal(5) // the number with value 5

        Type Parameters

        • T extends PrimitiveValue

        Parameters

        • literal: T

          Literal value.

        Returns IdentityType<T>

        T Literal value type.

  • maybe: (<T>(baseType: T) => T | IdentityType<undefined>)
      • <T>(baseType): T | IdentityType<undefined>
      • A type that represents either a type or undefined. Syntactic sugar for types.or(baseType, types.undefined)

        Example:

        const numberOrUndefinedType = types.maybe(types.number)
        

        Type Parameters

        Parameters

        • baseType: T

          Type.

        Returns T | IdentityType<undefined>

        T Type.

  • maybeNull: (<T>(type: T) => T | IdentityType<null>)
      • <T>(type): T | IdentityType<null>
      • A type that represents either a type or null. Syntactic sugar for types.or(baseType, types.null)

        • Example:
        const numberOrNullType = types.maybeNull(types.number)
        

        Type Parameters

        Parameters

        • type: T

          Type.

        Returns T | IdentityType<null>

        T Type.

  • model: (<M, K>(modelClass: _ClassOrObject<M, K>) => ModelType<K>)
      • <M, K>(modelClass): ModelType<K>
      • A type that represents a model. The type referenced in the model decorator will be used for type checking.

        Example:

        const someModelType = types.model(SomeModel)
        // or for recursive models
        const someModelType = types.model<SomeModel>(() => SomeModel)

        Type Parameters

        • M = never
        • K = M

        Parameters

        • modelClass: _ClassOrObject<M, K>

          Model class.

        Returns ModelType<K>

        M Model type.

  • nonEmptyString: IdentityType<string>
  • null: IdentityType<null>
  • number: IdentityType<number>
  • object: (<T>(objectFunction: T) => T)
      • <T>(objectFunction): T
      • A type that represents a plain object. Note that the parameter must be a function that returns an object. This is done so objects can support self / cross types.

        Example:

        // notice the ({ ... }), not just { ... }
        const pointType = types.object(() => ({
        x: types.number,
        y: types.number
        }))

        Type Parameters

        • T

        Parameters

        • objectFunction: T

          Function that generates an object with types.

        Returns T

        T Type.

  • objectMap: (<T>(valueType: T) => ModelType<ObjectMap<TypeToData<T>>>)
  • or: {
        <T>(dispatcher: ((sn: any) => T[number]), ...orTypes: T): T[number];
        <T>(...orTypes: T): T[number];
    }
      • <T>(dispatcher, ...orTypes): T[number]
      • A type that represents the union of several other types (a | b | c | ...). Accepts a dispatcher that, given a snapshot, returns the type that snapshot is.

        Type Parameters

        Parameters

        • dispatcher: ((sn: any) => T[number])

          Function that given a snapshot returns the type.

            • (sn): T[number]
            • Parameters

              • sn: any

              Returns T[number]

        • Rest...orTypes: T

          Possible types.

        Returns T[number]

        T Type.

      • <T>(...orTypes): T[number]
      • A type that represents the union of several other types (a | b | c | ...).

        Example:

        const booleanOrNumberType = types.or(types.boolean, types.number)
        

        Type Parameters

        Parameters

        • Rest...orTypes: T

          Possible types.

        Returns T[number]

        T Type.

  • record: (<T>(valueType: T) => RecordType<T>)
      • <T>(valueType): RecordType<T>
      • A type that represents an object-like map, an object with string keys and values all of a same given type.

        Example:

        // { [k: string]: number }
        const numberMapType = types.record(types.number)

        Type Parameters

        Parameters

        • valueType: T

          Type of the values of the object-like map.

        Returns RecordType<T>

        T Type.

  • ref: (<O>(refConstructor: RefConstructor<O>) => ModelType<Ref<O>>)
      • <O>(refConstructor): ModelType<Ref<O>>
      • A type that represents a reference to an object or model.

        Example:

        const refToSomeObject = types.ref(SomeObject)
        

        Type Parameters

        • O extends object

        Parameters

        Returns ModelType<Ref<O>>

        O Object or model type.

  • refinement: (<T>(baseType: T, checkFn: ((data: TypeToData<T>) => null | boolean | TypeCheckError), typeName?: string) => T)
      • <T>(baseType, checkFn, typeName?): T
      • A refinement over a given type. This allows you to do extra checks over models, ensure numbers are integers, etc.

        Example:

        const integerType = types.refinement(types.number, (n) => {
        return Number.isInteger(n)
        }, "integer")

        const sumModelType = types.refinement(types.model(Sum), (sum) => {
        // imagine that for some reason sum includes a number 'a', a number 'b'
        // and the result

        const rightResult = sum.a + sum.b === sum.result

        // simple mode that will just return that the whole model is incorrect
        return rightResult

        // this will return that the result field is wrong
        return rightResult ? null : new TypeCheckError(["result"], "a+b", sum.result)
        })

        Type Parameters

        Parameters

        • baseType: T

          Base type.

        • checkFn: ((data: TypeToData<T>) => null | boolean | TypeCheckError)

          Function that will receive the data (if it passes the base type check) and return null or false if there were no errors or either a TypeCheckError instance or true if there were.

        • OptionaltypeName: string

        Returns T

        T Base type.

  • string: IdentityType<string>
  • tag: (<T, A>(baseType: T, tag: A, typeName?: string) => T)
      • <T, A>(baseType, tag, typeName?): T
      • Wrap a given type with tag information. This allows you to associate metadata with the type of a prop that you can use at runtime.

        Example:

        const widthType = types.tag(types.number, { displayName: "Width in Inches", required: true }, "dimension")
        const heightType = types.tag(types.number, { displayName: "Height in Inches", required: true }, "dimension")

        These can then be accessed at runtime through inspection APIs, e.g.

        @model('MyModel')
        class MyModel extends Model({
        width: tProp(widthType, 10),
        height: tProp(heightType, 10)
        }) {}

        const m = new MyModel({})
        const type = types.model<typeof Model>(m.constructor)
        const modelTypeInfo = getTypeInfo(type) as ModelTypeInfo
        const propTypeInfo = modelTypeInfo.props.width.typeInfo as TagTypeInfo
        const displayName = propTypeInfo.displayName

        Type Parameters

        Parameters

        • baseType: T

          Base type.

        • tag: A

          Abitrary object that can be queried at runtime.

        • OptionaltypeName: string

        Returns T

        T Base type.

        A Tag object.

  • tuple: (<T>(...itemTypes: T) => ArrayType<T>)
      • <T>(...itemTypes): ArrayType<T>
      • A type that represents an tuple of values of a given type.

        Example:

        const stringNumberTupleType = types.tuple(types.string, types.number)
        

        Type Parameters

        Parameters

        • Rest...itemTypes: T

        Returns ArrayType<T>

        T Item types.

  • unchecked: (<T>() => IdentityType<T>)
      • <T>(): IdentityType<T>
      • A type that represents a given value that won't be type checked. This is basically a way to bail out of the runtime type checking system.

        Example:

        const uncheckedSomeModel = types.unchecked<SomeModel>()
        const anyType = types.unchecked<any>()
        const customUncheckedType = types.unchecked<(A & B) | C>()

        Type Parameters

        • T = never

        Returns IdentityType<T>

        T Type of the value, or unkown if not given.

  • undefined: IdentityType<undefined>
  • mapArray:function
  • mapObject:function
  • setArray:function