The capture function used in buildCancellablePromise helper function hides the type that is passed to it.
The capture function should act as an identity function from type perspective.
The use-case is that CancellablePromise<T> might be subclassed or enhanced with some additional information, such as progress reporting. We need the enhancements to be preserved when the an enhanced CancellablePromise is passed through the capture function.
Before the fix, the return type from capture would be a bare CancellablePromise<T>, hiding any additional features of the particular type that inherited from CancellablePromise<T> and was passed to capture.
This issue is shown in the automted compile-time test that is part of this PR. The step $ yarn tsc fails when the test is run on the original codebase, but passes after the proposed fix.
Thanks for your work on the real-cancellable-promise package! I am happy I finally found a solid solution to the promise cancellation problem.
The
capture
function used inbuildCancellablePromise
helper function hides the type that is passed to it.The
capture
function should act as an identity function from type perspective.The use-case is that
CancellablePromise<T>
might be subclassed or enhanced with some additional information, such as progress reporting. We need the enhancements to be preserved when the an enhanced CancellablePromise is passed through thecapture
function.Before the fix, the return type from
capture
would be a bareCancellablePromise<T>
, hiding any additional features of the particular type that inherited fromCancellablePromise<T>
and was passed tocapture
.This issue is shown in the automted compile-time test that is part of this PR. The step
$ yarn tsc
fails when the test is run on the original codebase, but passes after the proposed fix.Thanks for your work on the
real-cancellable-promise
package! I am happy I finally found a solid solution to the promise cancellation problem.