Within my TypeScript application, I am utilizing a Promise<void>
that is stored as a class-wide variable. There are scenarios where a method within the same class may call this promise and either wait for it to be resolved or rejected, but oftentimes no one is actually listening for these outcomes. As a result, when the promise is started without any listeners in place, an error message appears in the console:
Uncaught (in promise) undefined
The job carried out by the promise executes successfully despite this error message appearing. My main concern is understanding the significance of this error message. Is it safe to assume that the error occurs simply because there are no listeners set up to resolve or reject the promise, allowing it to run autonomously? Additionally, is there a way to prevent this error message from being displayed?
This is how the promise declaration looks like:
private apiInitialization: Promise<void>;
...
this.apiInitialization = new Promise<void>((resolve, reject) => {
this.siteService.requestInitialization().then((response: RequestResponse) => {
// Perform necessary actions.
// Resolve promise.
resolve();
}).catch(() => {
// Reject promise.
reject();
});
});