Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix capture function to preserve type identity #4

Conversation

ondrej-stanek-ozobot
Copy link
Contributor

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 should pass-through any type it is given,
in fact, it should act as an identity-function from the type perspective.
It should act as an identity function from type perspective.

The use-case is that CancellablePromise might be enhanced with some additional
information, such as progress reporting. We need the enhancements
to be preserved when the promise 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>.
@ondrej-stanek-ozobot ondrej-stanek-ozobot force-pushed the fix-capture-function-to-preserve-type-identity branch from 6c52548 to 36558d4 Compare January 18, 2023 14:02
Copy link
Owner

@srmagura srmagura left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @ondrej-stanek-ozobot, thanks for this change! It looks good.

Can you fix the Prettier and ESLint issues in the code you added to utils.test.ts? Once that is resolved, I will merge and deploy a new version.

@ondrej-stanek-ozobot
Copy link
Contributor Author

Sure, no problem, please review the fixes.

@srmagura srmagura merged commit ee4eb6b into srmagura:main Jan 23, 2023
@srmagura
Copy link
Owner

Just published 1.1.2 to npm. Thanks for your contribution :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants