angular - Angular2 promise - returning functions that already return a promise -
i've written following function - i'm trying return existing promise functions without needed wrap them in custom promise:
doauthwithprompt(): promise <any> { this.getuser() // returns promise .then (user => { if (user == undefined) { this.promptforpassword() // returns promise .then (data => { return this.doauth(data.email, data.password); // returns promise }) } else { return this.doauth(user.email, user.password) // returns promise }; }) .catch (e => {return promise.reject(false);}) }
the error getting in ide (visual studio code) is:
[ts] function declared type neither 'void' nor 'any' must return value.
what missing while defining doauthwithprompt
? thanks.
you need return wrapper promise
, chained promises also:
doauthwithprompt(): promise <any> { return this.getuser() // returns promise .then (user => { if (user == undefined) { return this.promptforpassword() // returns promise .then (data => { return this.doauth(data.email, data.password); // returns promise }) } else { return this.doauth(user.email, user.password) // returns promise } }) .catch (e => {return promise.reject(false);}) }
Comments
Post a Comment