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!
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.
Comments