Promise returning a function instead of an object

milestrong

I am using the node module fbgraph in order to retrieve data from a Facebook user and create an account in our app.

I have the following code which is wrapped inside an async function:

const newUser = await new Promise((resolve, reject) => {
  graph.get(url, (err, res) => {
    if (err) {
      return reject(err);
    }

    const user = new User();
    user.firstName  = res.first_name;
    user.lastName   = res.last_name;
    user.email      = res.email;

    return resolve(user);
  });
});

this.register(newUser);

I am unable to pass the newUser variable to my register function, and am getting this error:

Argument of type '{}' is not assignable to parameter of type 'User'.

Upon logging newUser, it appears to be the correct User object I am expecting, but when I log newUser.constructor it appears that what's actually being returned is a [Function: User]

I'm not particularly experienced with Promises, and I feel like the problem lies somewhere there. Any help is greatly appreciated!

Zbigniew Zagórski

Typescript cannot infer actual promise type, so defaults to something - in this case {}.

You should be explicit about Promise and create Promise<User> type i.e

const newUser = await new Promise<User>((resolve, reject) => {
    //...
})

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Function is returning object Promise - nodejs

From Dev

Returning [object Promise] instead of actual value

From Dev

Async function returning promise, instead of value

From Dev

jwplayer returning function instead of player object

From Dev

React.CloneElement returning an object instead of function

From Dev

Contract function returning a transaction object instead of a BOOL

From Dev

Reduce function returning an object instead of an array

From Dev

Axios API call returning Promise object instead of result?

From Javascript

Why is my asynchronous function returning Promise { <pending> } instead of a value?

From Javascript

Why is my asynchronous function returning Promise { <pending> } instead of a value?

From Dev

Why is my function returning a Promise { <pending> } instead of my entries?

From Dev

Recursive function in Redux/Thunk returning Promise object, not regular object

From Dev

Promise object not returning a value

From Dev

Axios returning a promise object

From Dev

Stub function returning promise

From Dev

function not returning with promise

From Dev

Returning promise of then not a function

From Dev

Returning a recursive function with a promise

From Dev

Promise function not returning results

From Dev

What is the advantage of returning an object in a static function instead of building it?

From Dev

dialogflow nodejs function returning empty object instead of string

From Dev

Pytest fixture command line returning function object instead of value

From Dev

Returning Future<Object> instead of Object

From Javascript

Returning an object with a promise (resolve, reject)

From Dev

Axios request returning promise Object

From Dev

Why is this promise returning an [object Promise] and not the value?

From Dev

Promise `then` with a function returning nothing vs with a function returning an another promise

From Dev

Returning a promise nested in forEach, in a .then function

From Dev

resolve() function is returning undefined in a promise

Related Related

  1. 1

    Function is returning object Promise - nodejs

  2. 2

    Returning [object Promise] instead of actual value

  3. 3

    Async function returning promise, instead of value

  4. 4

    jwplayer returning function instead of player object

  5. 5

    React.CloneElement returning an object instead of function

  6. 6

    Contract function returning a transaction object instead of a BOOL

  7. 7

    Reduce function returning an object instead of an array

  8. 8

    Axios API call returning Promise object instead of result?

  9. 9

    Why is my asynchronous function returning Promise { <pending> } instead of a value?

  10. 10

    Why is my asynchronous function returning Promise { <pending> } instead of a value?

  11. 11

    Why is my function returning a Promise { <pending> } instead of my entries?

  12. 12

    Recursive function in Redux/Thunk returning Promise object, not regular object

  13. 13

    Promise object not returning a value

  14. 14

    Axios returning a promise object

  15. 15

    Stub function returning promise

  16. 16

    function not returning with promise

  17. 17

    Returning promise of then not a function

  18. 18

    Returning a recursive function with a promise

  19. 19

    Promise function not returning results

  20. 20

    What is the advantage of returning an object in a static function instead of building it?

  21. 21

    dialogflow nodejs function returning empty object instead of string

  22. 22

    Pytest fixture command line returning function object instead of value

  23. 23

    Returning Future<Object> instead of Object

  24. 24

    Returning an object with a promise (resolve, reject)

  25. 25

    Axios request returning promise Object

  26. 26

    Why is this promise returning an [object Promise] and not the value?

  27. 27

    Promise `then` with a function returning nothing vs with a function returning an another promise

  28. 28

    Returning a promise nested in forEach, in a .then function

  29. 29

    resolve() function is returning undefined in a promise

HotTag

Archive