Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

cannot call promise inside of function: "has no call signatures"

I have this class:

export class ExponentialBackoffUtils {
    public static retry(promise: Promise<any>, maxRetries: number, onRetry?: Function) {
        function waitFor(milliseconds: number) {
            return new Promise((resolve) => setTimeout(resolve, milliseconds));
        }
        async function retryWithBackoff(retries: number) {
            try {
                if (retries > 0) {
                    const timeToWait = 2 ** retries * 1000;
                    await waitFor(timeToWait);
                }
                console.log('Retries: ', retries);
                if (retries < 3) {
                    throw new Error();
                }
                return await promise();
            } catch (e) {
                if (retries < maxRetries) {
                    if (onRetry) {
                        onRetry();
                    }
                    return retryWithBackoff(retries + 1);
                } else {
                    throw e;
                }
            }
        }

        return retryWithBackoff(0);
    }
}

Typescript is yelling at me saying I can’t call the promise that I pass in……why? It says that promise has no call signatures.

enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

A Promise is not a function, so you cannot call it with the promise() syntax.

It should be sufficient for you to simply await promise without the brackets.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading