Syntax error on app/app.component.ts - (82,40): error TS2339: Property 'then' does not exist on type 'void'.​​

3,913 views
Skip to first unread message

John

unread,
Jun 10, 2017, 8:30:04 AM6/10/17
to Angular and AngularJS discussion

Hi there, 

When I start the app with #npm start, the app does not start. It gives the following errors below..........


(1) (82,40): error TS2339: Property 'then' does not exist on type 'void'. 


(2) Parameter 'account' implicitly has an 'any type


The entire  code base of  app/app.component.ts is clean, except the two words from the snippet below are underlined......  "then"  is underlined and   "account" is underlined.

  private removeAcc(index:number){
    this._accountService.remove(index).then(account => console.log(account));
  }


Sander Elias

unread,
Jun 10, 2017, 9:02:52 AM6/10/17
to Angular and AngularJS discussion
Hi John,

probably, your remove function doesn't return a promise. 

Regards
Sander

John Kimathi

unread,
Jun 10, 2017, 9:36:18 AM6/10/17
to ang...@googlegroups.com
Thank you Sanders,

Here below is the remove method of the Promise.

  public remove(index:number){
  if(this._logger)
    this._logger.log('Account deleted: ' + this._accounts[index].title);

  this._accounts.splice(index, 1);
  }
}



and here below is the entire Promise base. Please have a look, advice further.

public getAll():Promise<Array<Account>>{
      return Promise.resolve(this._accounts);
    }

    private _nextId = 3;
    private _accountLimit = 3;
    public create(newAccount:Account){

      return new Promise((resolve,reject) => {
        if(this._accounts.length >= this._accountLimit)
          return reject("Maximum accounts limit reached.");

      newAccount.id = this._nextId++;
      if(this._logger)
        this._logger.log('Account created: ' + newAccount.title);
      this._accounts.push(newAccount);
      resolve(newAccount);
   });
}
  public remove(index:number){
  if(this._logger)
    this._logger.log('Account deleted: ' + this._accounts[index].title);

  this._accounts.splice(index, 1);
  }
}






--
You received this message because you are subscribed to the Google Groups "Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to angular+unsubscribe@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Sander Elias

unread,
Jun 10, 2017, 11:34:36 AM6/10/17
to Angular and AngularJS discussion
Indeed, it does not return a promise. You can't put a .then on a void the error is spot on.

Regards
Sander

John

unread,
Jun 10, 2017, 2:22:49 PM6/10/17
to Angular and AngularJS discussion

John

unread,
Jun 10, 2017, 2:30:22 PM6/10/17
to Angular and AngularJS discussion
Hi there,

I have not been able to resolve the error "Property 'then' does not exist on type 'void'".

I here by attach the two files. The file, app.component.ts, is the one which contains the problematic  snippet
below....

  private removeAcc(index:number){
   this._accountService.remove(index).then(account => console.log(account));
}

Any help to get it resolved  highly appreciated.

Thanks & Regards,
John.

 


On Saturday, 10 June 2017 17:34:36 UTC+2, Sander Elias wrote:
account.services.ts
app.component.ts
Reply all
Reply to author
Forward
0 new messages