Working on an e-commerce website, I encountered errors in the "cartservice" specifically in the "checkoutFromCart()" function. The console displayed the following error:
src/app/services/cart.service.ts:218:81
218 this.http.post(${this.serverUrl}orders/payment
, null).subscribe((res: { success: boolean }) => {
~~~~~~~
'success' is declared here.
Error: src/app/services/cart.service.ts:228:24 - error TS2769: No overload matches this call. Overload 1 of 5, '(observer?: NextObserver | ErrorObserver | CompletionObserver | undefined): Subscription', gave the following error. Argument of type '(data: orderResponse) => void' is not assignable to parameter of type 'NextObserver | ErrorObserver | CompletionObserver | undefined'. Property 'complete' is missing in type '(data: orderResponse) => void' but required in type 'CompletionObserver'. Overload 2 of 5, '(next?: ((value: Object) => void) | undefined, error?: ((error: any) => void) | undefined, complete?: (() => void) | undefined): Subscription', gave the following error. Argument of type '(data: orderResponse) => void' is not assignable to parameter of type '(value: Object) => void'. Types of parameters 'data' and 'value' are incompatible. The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead? Type 'Object' is missing the following properties from type 'orderResponse': order_id, success, message, products
228 }).subscribe((data:orderResponse) => { [91m ~~~~~~~~~~~~~~~~~~~~~~~~~
node_modules/rxjs/internal/types.d.ts:73:5 73 complete: () => void; ~~~~~~~~ 'complete' is declared here.
my code: checkoutFonction
console error: error
I apologize for any mistakes in my question as I am new to Stack Overflow, but I am in need of assistance.
Apologies for the images. Here is the code snippet:
CheckoutFromCart(userId: number) {
this.http.post(`${this.serverUrl}orders/payment`, null).subscribe((res:{ success: boolean }) => {
console.clear();
if (res.success) {
this.resetServerData();
this.http.post(`${this.serverUrl}orders/new`, {
userId: userId,
products: this.cartDataClient.prodData
}).subscribe((data:orderResponse) => {
this.orderservice.getSingleOrder(data.order_id).then(prods => {
if (data.success) {
const navigationExtras: NavigationExtras = {
state: {
message: data.message,
products: prods,
orderId: data.order_id,
total: this.cartDataClient.total
}
};
this.router.navigate(['/thankyou'], navigationExtras).then(p => {
this.cartDataClient = {prodData: [{incart: 0, id: 0}], total: 0};
this.cartTotal$.next(0);
localStorage.setItem('cart', JSON.stringify(this.cartDataClient));
});
}
});
})
} else {
this.router.navigateByUrl('/checkout').then();
}
})
}