I have encountered an issue while working with a reactive form. I am able to append text or files from the form in order to make an http
post request successfully. However, I am unsure about how to properly append values like dates, booleans, or arrays.
addPost(postAdded: Post, image: File) {
const postData = new FormData();
postData.append("title", postAdded.title); // string
postAdded.append("startDate", postAdded.startDate); // date
postAdded.append("private", postAdded.private); // boolean
postAdded.append("image", image, postAdded.title); // file
this.http
.post<{ postId: string }>(
"http://localhost:3000/api/posts",
postAdded
)
.subscribe(responseData => {
this.potsUpdated.next([...this.posts]);
this.router.navigate(["/"]);
});
}
The error message I'm receiving is:
Argument of type 'Date' is not assignable to parameter of type 'string | Blob'. Type 'Date' is not assignable to type 'string'.ts(2345)
or
Argument of type 'boolean' is not assignable to parameter of type 'string | Blob'.ts(2345)
and finally the error for array
Argument of type 'string[]' is not assignable to parameter of type 'string | Blob'. Type 'string[]' is not assignable to type 'string'.ts(2345)
When dealing with booleans
The booleans are used for toggles, and dates are intended for datepickers.
Any suggestions on how to handle this?