Avinash Kumar
Avinash Kumar

Reputation: 81

Type 'void' is not assignable to type 'FormData'

I m using FormData in angular 5, but it gives error given below.

   approvalUser(userId): Observable<any> {
    let formData = new FormData();
    formData = formData.append('id',userId); error in this line shows==> "Type 'void' is not assignable to type 'FormData' " 
    return this.http.post<any>(this.url.APPOROVAL_USER,formData);
  }

Upvotes: 2

Views: 3396

Answers (1)

iamcastelli
iamcastelli

Reputation: 1774

Because FormData.append() does not return anything. So it returns void.

Essential your statement formData = formData.append('id',userId); is invalid as you are assigning a void type to FormData type.

Look at FormData.append().

Remove the assignee and you will be good.


approvalUser(userId): Observable<any> {
   let formData = new FormData();
   formData.append('id',userId);

   return this.http.post<any>(this.url.APPOROVAL_USER,formData);
  }

Upvotes: 5

Related Questions