-
Notifications
You must be signed in to change notification settings - Fork 585
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Type 'ListType<string> | List<string[]>' is not assignable to type '(string | Unmanaged<string, never>)[] | undefined'. #6292
Comments
Should |
Yes, it should. I tried to make my example generic and forgot to edit that part. |
I have reopened the issue |
Hi @szkieb, the Since you want to use default values, an alternative to what you have is to define the defaults directly in the schema (also note that you don't need to explicitly set class MyClass extends Realm.Object<MyClass> {
// Don't forget the `!`.
myClassId!: string;
images!: Realm.List<string>;
static schema: Realm.ObjectSchema = {
name: "MyClass",
primaryKey: "myClassId",
properties: {
myClassId: { type: "string", default: () => new BSON.ObjectId().toString() },
images: { type: "list", objectType: "string", default: [] },
},
};
constructor(realm: Realm, properties: Partial<Report>) {
super(realm, properties);
}
}
// After having opened the realm...
realm.write(() => {
new MyClass(this.realm, {
// Any required properties..
});
}); It's also common to skip the constructor in the class and pass in object literals when adding it to the realm: class MyClass extends Realm.Object<MyClass> {
myClassId!: string;
images!: Realm.List<string>;
static schema: Realm.ObjectSchema = {
name: "MyClass",
primaryKey: "myClassId",
properties: {
myClassId: { type: "string", default: () => new BSON.ObjectId().toString() },
images: { type: "list", objectType: "string", default: [] },
},
};
}
// After having opened the realm...
realm.write(() => {
realm.create(MyClass, {
// Any required properties..
});
}); Let us know if this helps you. |
Closing due to inactivity. |
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 type. I expect the interface, schema and constructor to work together and be compatible but the types don't match up.
Stacktrace & log output
Can you reproduce the bug?
Always
Reproduction Steps
I write a class like in the example below.
I set a default value in the constructor resulting in this error.
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
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
The text was updated successfully, but these errors were encountered: