-
Type: Bug
-
Resolution: Works as Designed
-
Priority: Minor - P4
-
None
-
Affects Version/s: None
-
Component/s: None
How frequently does the bug occur?
Always
Description
Creating a class with one property being an array of strings for which I used the RealmList<string> type. I expect the interface, schema and constructor to work together and be compatible but the types don't match up.
Stacktrace & log output
Type 'ListType<string> | List<string[]>' is not assignable to type '(string | Unmanaged<string, never>)[] | undefined'. Type 'List<string>' is missing the following properties from type '(string | Unmanaged<string, never>)[]': reverse, sort, fill, copyWithin, and 6 more.ts(2322)
Can you reproduce the bug?
Always
Reproduction Steps
I write a class like in the example below.
export class MyClass extends Realm.Object<MyClass> { myClassId: string; ... images!: Realm.List<string>; ... public static schema: Realm.ObjectSchema = { name: 'MyClass', primaryKey: 'myClassId', properties: { myClassId: string, ... images: { type: 'list', objectType: 'string', optional: false }, ... } } constructor(realm: Realm, properties: Partial<Report>) { super(realm, { myClassId: properties.myClassId || new BSON.ObjectID().toString(), ... images: properties.images || new Realm.List<string[]>(), ...
I set a default value in the constructor resulting in this error.
Type 'ListType<string> | List<string[]>' is not assignable to type '(string | Unmanaged<string, never>)[] | undefined'. Type 'List<string>' is missing the following properties from type '(string | Unmanaged<string, never>)[]': reverse, sort, fill, copyWithin, and 6 more.ts(2322)
What is funny is even though I define the property as realm list and I construct it as such it somehow complains that it ought be 'unmanaged' and unmanaged is not well documented as far as I can tell. If I am doing something wrong I would at like the documentation to be clearer on (1) best practices or (im)possibilities of creating string arrays as properties and (2) creating default values in typescript esp. complex types such as realm lists and embedded objects.
Version
"realm": "^12.3.1",
What services are you using?
Local Database only
Are you using encryption?
Yes
Platform OS and version(s)
iOS 17, expo 48
Build environment
No response
Cocoapods version
No response
edited example code