It appears that in the realm of JavaScript, one has the capability to execute:
function extendPromise(promise) {
return promise.then(new Promise(() => {}));
}
However, when incorporating types into the mix, such as
function extendTypeScriptPromise(promise: Promise<void>) {
return promise.then(new Promise<void>(() => {}));
}
the TypeScript compiler raises an objection:
error TS2345: Argument of type 'Promise<void>' is not assignable to parameter of type '((value: void) => void | PromiseLike<void>) | null | undefined'.
Type 'Promise<void>' is not assignable to type '(value: void) => void | PromiseLike<void>'.
Type 'Promise<void>' provides no match for the signature '(value: void): void | PromiseLike<void>'.
Why isn't a Promise<void>
accepted as PromiseLike
?