Fix capture
function to preserve type identity
#4
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.