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

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -