You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Realm.Object.linkingObjects() method, when given a class-based model as a type argument, does not infer the correct TypeScript type for the collection that it returns.
The method does not allow you to specify the class-based model, though this would be a welcome improvement and in line with the API for Realm.objects, useObject, etc.
// ✅ The useObject hook correctly infers the `Post` type based on the class I pass inconstpost=useObject(Post,_id)!;// Post & Realm.Object<Post, never>// ⛔️ This doesn't work - the first arg must be a string - but it would be idealconstuser=post.linkingObjects(User,'posts')[0]!;// User & Realm.Object<User, never>// This runs but it uses the class _name_ as a string and doesn't infer the correct return typeconstuser=post.linkingObjects('User','posts')[0]!;// Realm.Object<unknown, never>// This runs and assigns a half correct type but still uses class name + a type castconstuser=post.linkingObjects<User>('User','posts')[0]!;// User & Realm.Object<unknown, never>
Stacktrace & log output
No response
Can you reproduce the bug?
Always
Reproduction Steps
Create a Realm.Object class with a relationship to another class.
realm.write(()=>{constfoo=realm.create(Foo,{_id: newRealm.BSON.ObjectId(),name: "Winnie the Foo Bear"})constbar1=realm.create(Bar,{_id: newRealm.BSON.ObjectId(),name: "Honey"})constbar2=realm.create(Bar,{_id: newRealm.BSON.ObjectId(),name: "Smile"})foo.bars.push(bar1)foo.bars.push(bar2)})
Get a collection of backlinks for the relationship using linkingObjects()
constbars=realm.objects(Bar);constbar0=bars[0]!// ERROR: Argument of type 'typeof User' is not assignable to parameter of type 'string'.constlinkingFoos=bar0.linkingObjects(Foo,"bars")!;// BUG: TS Type is not correctconstlinkingFoos: Realm.Results<Realm.Object<unknown,never>>=bar0.linkingObjects('Foo',"bars")!;
Version
11.4.0
What services are you using?
Local Database only
Are you using encryption?
No
Platform OS and version(s)
macOS Monterey (12.6.2)
Build environment
No response
Cocoapods version
No response
The text was updated successfully, but these errors were encountered:
How frequently does the bug occur?
Always
Description
The
Realm.Object.linkingObjects()
method, when given a class-based model as a type argument, does not infer the correct TypeScript type for the collection that it returns.The method does not allow you to specify the class-based model, though this would be a welcome improvement and in line with the API for
Realm.objects
,useObject
, etc.Stacktrace & log output
No response
Can you reproduce the bug?
Always
Reproduction Steps
Realm.Object
class with a relationship to another class.linkingObjects()
Version
11.4.0
What services are you using?
Local Database only
Are you using encryption?
No
Platform OS and version(s)
macOS Monterey (12.6.2)
Build environment
No response
Cocoapods version
No response
The text was updated successfully, but these errors were encountered: