Start a new topic

Kinvey user-oriented query - lookup problem

I have searched a lot on Google, but nothing ... I think that there is a mistake with the code, which is describing the User Discovery section here: https://devcenter.kinvey.com/angular/guides/users#lookup


When I try to execute Kinvey.User.lookup(query).subscribe method, I get this error: 


Property 'subscribe' does not exist ont type 'Promise<{}>'


Any ideas how to fix this error so I can get users data?


This worked for me! Thank you so much!

Hi Albert,

Indeed the TypeScript definitions are wrongly set that the lookup method returns a Promise when it would return an observable. I have logged this as a bug - thank you for reporting this.

As a workaround, you may cast the method as returning an observable or any like this:


var subscription = (Kinvey.User.lookup(query) as any).toPromise();
                subscription
                .then((user: Kinvey.User) => {
                        console.log('here', JSON.stringify(user));
                    })
                    .catch(err => {
                        console.log('err', JSON.stringify(err));
                    });


or like this:

const subscription =(Kinvey.User.lookup(query) as any)
  .subscribe((user: Kinvey.User) => {
    console.log('here', JSON.stringify(user));
  });


Let me know if this has helped.


1 person likes this

My project is very simple. I am using NativeScript with Angular 2 and TypeScript.


Now I can see in the node_modules \ kinvey-nativescript-sdk \ kinvey.d.ts that line of code:


 

static lookup(query?: Query, options?: RequestOptions): Promise<{}>;


When I change Promise<{}> to Observable<{}>, the error does not show, but how can I get the users output?

Hi Albert,


I tried to reproduce the described behavior but without any success. The User.lookup() method will return an observable, not a promise as stated in the documentation and as you can see in the source code here: https://github.com/Kinvey/js-sdk/blob/master/src/core/user/userstore.js#L62.


Could you please send a sample project you are testing with in order to replicate the issue?


Regards

Martin Apostolov

Login or Signup to post a comment