Type alias PropertySchema

PropertySchema: {
    default?: unknown;
    indexed?: IndexedType;
    mapTo?: string;
    objectType?: PrimitivePropertyTypeName | UserTypeName;
    optional?: boolean;
    property?: string;
    type: PropertyTypeName;
}

The schema for specifying the type of a specific Realm object property.

Requirements:

  • "mixed" types are always optional because null is a valid value within "mixed" itself. Therefore, they cannot be made non-optional.
  • User-defined object types are always optional except in lists and sets due to the object being deleted whenever it is removed from lists and sets and are therefore never set to null or undefined. Whereas in in dictionaries, deleted values are set to null and cannot be made non-optional.
  • Properties declared as the primary key in ObjectSchema.primaryKey are always indexed. In such cases, they cannot be made non-indexed.

Type declaration

  • Optional default?: unknown

    The default value that the property will be set to when created.

  • Optional indexed?: IndexedType

    The type of index applied to the property.

    Default value: false if the property is not a primary key, otherwise true.

  • Optional mapTo?: string

    The name to be persisted in the Realm file if it differs from the already-defined JavaScript/TypeScript (JS/TS) property name. This is useful for allowing different naming conventions than what is persisted in the Realm file. Reading and writing properties must be done using the JS/TS name, but queries can use either the JS/TS name or the persisted name.

  • Optional objectType?: PrimitivePropertyTypeName | UserTypeName

    The type of the elements in the collection if type is a CollectionPropertyTypeName, or the specific Realm object type if type is a RelationshipPropertyTypeName.

  • Optional optional?: boolean

    Whether to allow null or undefined to be assigned to the property; or in the case of a collection, to be assigned to its elements. (Realm object types in lists and sets cannot be optional.)

    Default value: false except in cases listed in the documentation for this type.

  • Optional property?: string

    The name of the property of the object specified in objectType that creates this link. (Can only be set for linking objects.)

  • type: PropertyTypeName

    The type of the property.

See

  • PropertySchemaShorthand for a shorthand representation of a property schema.
  • PropertySchemaStrict for a precise type definition of the requirements with the allowed combinations. This type is less strict in order to provide a more user-friendly option due to misleading TypeScript error messages when working with the strict type. This type is currently recommended for that reason, but the strict type is provided as guidance. (Exact errors will always be shown when creating a Realm instance if the schema is invalid.)

Generated using TypeDoc