Andurit Andurit - 1 year ago 267
TypeScript Question

Angular2 - 'then' does not exist on type 'void'

I try simple app where I delete user after clicking on delete button.

When I try to run server like this I get error on



deleteUser(user: User, event: any) {
.then(res => {
this.httpUsers = this.httpUsers.filter(h => h !== user);
if (this.selectedUser === user) { this.selectedUser = null; }
.catch(error => this.error = error);


deleteUser(user: User) {
console.log('Deleting user');

Error message:

app/users.component.ts(46,8): error TS2339: Property 'then' does not
exist on type 'void'.

Line 46 from error is one above with
.then(res => {

While googling I found this question so I removed void from deleteUser function, however nothing changed.

Any hint what I'm doing wrong?

Answer Source

The deleteUser method in your service doesn't return a Promise, so you can't call .then(res => ...) on it, like the error states.

deleteUser(user: User) {
  console.log('Deleting user'); // <-- no return call - defaults to void
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download