question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Type 'void' is not assignable to type 'Promise<any>'. on authorizeOnServer example

See original GitHub issue

Hi!, using copy paste for example of authorizeOnServer, console return


Type '(approveData: IOnApproveCallbackData) => void' is not assignable to type '(data: IOnApproveCallbackData, actions: any) => Promise<any>'.
  Type 'void' is not assignable to type 'Promise<any>'.

what is wrong?

Regards!

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

6reactions
tebantebantebancommented, Apr 6, 2019

Finally, I’ve modify example :

this.payPalConfig = {
            currency: 'USD',
            clientId: 'XXXX',
            createOrderOnServer: (data) => fetch(this.sg['API']+'/Checkout', {method: 'post', 
                                                                              headers: {
                                                                                  'content-type': 'application/json'
                                                                                },
                                                                              body : JSON.stringify({ "products" : this.products,
                                                                                                   "checkoutForm" : checkoutForm,
                                                                                                   "hotelForm" : this.HotelDataForm.value,
                                                                                                   "dolar" : this.sg['appInfo'].dolar,
                                                                                                   "totalPesos" : this.sg['cartTotal'],
                                                                                                   "totalDolares" : this.sg['cartTotalDolar']
                                                                                                 })
                                                                             }
                                                )
               .then((res) => res.json())
               .then((order) => order.orderID),
            
            authorizeOnServer: (approveData) => 
                
                fetch(this.sg['API']+'/Checkout/result/paypal/'+approveData.orderID, {
                    method: 'post', 
                    headers: {
                      'content-type': 'application/json'
                    },
                    body: JSON.stringify({
                            orderID: approveData.orderID
                          }) 
                }).then((res) => {
                    return res.json();
                }).then((details) => {
                    this.zone.run(() => {/* my code here */
                        this.router.navigate(['/checkout-result/'+details.id], { relativeTo: this.route.parent });
                    });
                     
                })
            ,
            onApprove: (data, actions) => {
                console.log("APROBED", data)
            },
            onCancel: (data, actions) => {
                this.notificationBarService.create({ message: 'Cancelaste la transacción.', type: NotificationType.Warning});
                console.log('OnCancel', data, actions);
            },
            onError: err => {
                this.notificationBarService.create({ message: 'Ocurrió un error en el pago con PAYPAL. intenta nuevamente..', type: NotificationType.Error});
                console.log('OnError', err);
            },
            onClick: () => { 
                console.log('onClick');
            },
        };
  • Delete {} FROM authorizeOnServer
  • Add onApprove

And error disappear.

Thanks 😉.

0reactions
tebantebantebancommented, Apr 4, 2019

Sorry!, in the example

this.payPalConfig = {
            clientId: 'sb',
            // for creating orders (transactions) on server see
            // https://developer.paypal.com/docs/checkout/reference/server-integration/set-up-transaction/
            createOrderOnServer: (data) => fetch('/my-server/create-paypal-transaction')
                .then((res) => res.json())
                .then((order) => data.orderID),
            authorizeOnServer: (approveData) => {
                fetch('/my-server/authorize-paypal-transaction', {
                    body: JSON.stringify({
                    orderID: approveData.orderID
                    })
                }).then((res) => {
                    return res.json();
                }).then((details) => {
                    alert('Authorization created for ' + details.payer_given_name);
                });
            },
            onCancel: (data, actions) => {
                console.log('OnCancel', data, actions);
                this.showCancel = true;
            },
            onError: err => {
                console.log('OnError', err);
                this.showError = true;
            },
            onClick: () => {
                console.log('onClick');
                this.resetStatus();
            },
        };

My code

this.payPalConfig = {
            currency: 'USD',
            clientId: 'XXX',
            createOrderOnServer: (data) => fetch(this.sg['API']+'/Checkout', {method: 'post', 
                                                                              headers: {
                                                                                  'content-type': 'application/json'
                                                                                },
                                                                              body : JSON.stringify({ "products" : this.products,
                                                                                                   "checkoutForm" : checkoutForm,
                                                                                                   "hotelForm" : this.HotelDataForm.value,
                                                                                                   "dolar" : this.sg['appInfo'].dolar,
                                                                                                   "totalPesos" : this.sg['cartTotal'],
                                                                                                   "totalDolares" : this.sg['cartTotalDolar']
                                                                                                 })
                                                                             }
                                                )
               .then((res) => res.json())
               .then((order) => order.orderID),
            
            authorizeOnServer: (approveData) => {
                
                fetch(this.sg['API']+'/Checkout/result/paypal/'+approveData.orderID, {
                    method: 'post', 
                    headers: {
                      'content-type': 'application/json'
                    },
                    body: JSON.stringify({
                            orderID: approveData.orderID
                          }) 
                }).then((res) => {
                    return res.json();
                }).then((details) => {
                    this.zone.run(() => {
                        
                        this.router.navigate(['/checkout-result/'+details.id], { relativeTo: this.route.parent });
                    });
                     
                });
            },
            onCancel: (data, actions) => {
                this.notificationBarService.create({ message: 'Cancelaste la transacción.', type: NotificationType.Warning});
                console.log('OnCancel', data, actions);
            },
            onError: err => {
                this.notificationBarService.create({ message: 'Ocurrió un error en el pago con PAYPAL. intenta nuevamente..', type: NotificationType.Error});
                console.log('OnError', err);
            },
            onClick: () => { 
                console.log('onClick');
            },
        };

I don’t see the difference, what I missing?

Thanks you!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Type Promise<void> is not assignable to type ... - Stack Overflow
You are not returning anything inside your then which makes jobs be of type Promise<void> . Return the array inside then :
Read more >
Type 'void' is not assignable to type Promise<Note[]> - ionic-v3
I have this error and the errors show like TypeScript error: Type 'void' is not assignable to type Promise<Note[]> .
Read more >
Microsoft/TypeScript - Gitter
Type '<U>(onFulFill: (result: IUserDocument) => void, onReject?: (err: any) => void) => Promise<U>' is not assignable to type '{ <TResult>(onfulfilled?:
Read more >
CustomStore - The "Promise<Object> is not assignable to type ...
Hello I use a datagrid with an underlying customstore with following code : data: any = {}; this.data = new CustomStore({ key: ['id....
Read more >
Promise<T> returned by conditional type : r/typescript - Reddit
Type 'Promise<TQueryFnData>' is not assignable to type '[TQueryFnData] extends [undefined] ? "queryFn must not return undefined or void" ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found