Skip to content
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 error for mutableSubs.add with a collection referencing class based models #4477

Closed
takameyer opened this issue Apr 6, 2022 · 0 comments · Fixed by #4479
Closed

Type error for mutableSubs.add with a collection referencing class based models #4477

takameyer opened this issue Apr 6, 2022 · 0 comments · Fixed by #4479
Assignees
Labels

Comments

@takameyer
Copy link
Contributor

takameyer commented Apr 6, 2022

How frequently does the bug occur?

All the time

Description

When trying to add a subscription to a collection result, I get a type error if the collection query was based on class based models.

For example:

//works
realm.subscriptions.update(mutableSubs => {
  mutableSubs.add(realm.objects("Task"));
});

//doesn't work
realm.subscriptions.update(mutableSubs => {
  mutableSubs.add(realm.objects(Task));
});

My class:

export class Task extends Realm.Object {
  _id!: Realm.BSON.ObjectId;
  description!: string;
  isComplete!: boolean;
  createdAt!: Date;
  userId!: string;

  // To use a class as a Realm object type, define the object schema on the static property "schema".
  static schema = {
    name: 'Task',
    primaryKey: '_id',
    properties: {
      _id: 'objectId',
      description: 'string',
      isComplete: {type: 'bool', default: false},
      createdAt: 'date',
      userId: 'string',
    },
  };
}

Stacktrace & log output

Type error:

Argument of type 'Results<Task>' is not assignable to parameter of type 'Results<Task & Object>'.
  Type 'Task' is not assignable to type 'Task & Object'.
    Type 'Task' is not assignable to type 'Object'.
      Types of property 'addListener' are incompatible.
        Type '(callback: ObjectChangeCallback<Task>) => void' is not assignable to type '(callback: ObjectChangeCallback<Object>) => void'.
          Types of parameters 'callback' and 'callback' are incompatible.
            Types of parameters 'object' and 'object' are incompatible.
              Type 'Task' is not assignable to type 'Object'.
                Types of property 'addListener' are incompatible.
                  Type '(callback: ObjectChangeCallback<Task>) => void' is not assignable to type '(callback: ObjectChangeCallback<Object>) => void'.
                    Types of parameters 'callback' and 'callback' are incompatible.
                      Types of parameters 'changes' and 'changes' are incompatible.
                        Type 'ObjectChangeSet<Task>' is not assignable to type 'ObjectChangeSet<Object>'.
                          Type 'Object' is missing the following properties from type 'Task': _id, description, isComplete, createdAt, userIdts(2345)

Can you reproduce the bug?

Yes, always

Reproduction Steps

Version

10.12.0

What SDK flavour are you using?

MongoDB Realm (i.e. Sync, auth, functions)

Are you using encryption?

No, not using encryption

Platform OS and version(s)

macOS

Build environment

Which debugger for React Native: ..

Cocoapods version

No response

@takameyer takameyer added the T-Bug label Apr 6, 2022
@takameyer takameyer mentioned this issue Apr 6, 2022
9 tasks
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants