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

Update typings to explicitly not require a bound this #9

Merged
merged 1 commit into from
Apr 1, 2024

Conversation

JacobLey
Copy link
Contributor

If a user attempts to destructure the defer object, it can get flagged by @typescript-eslint/unbound-method.

The actual implementation does not at all require a reference to this (resolve+reject is the native value provided in the promise callback), but the typescript definitions do not make it clear, and since it is being pulled off a object, eslint thinks it might need a reference to this.

Example:

async () => {
    const { promise, resolve } = defer(); // eslint fails here

    setTimeout(() => resolve('<abc>'), 100);
    return promise;
};

(This example is an oversimplification, and not a great place to legitimately use this library, but enough to recreate the issue)

The solution is to just update the typing to explicitly declare the this as ignorable (void).

@JacobLey
Copy link
Contributor Author

Looks like tests are failing on linter checks for node_modules. Not relevant for this change I believe

@sindresorhus sindresorhus merged commit a6661a0 into sindresorhus:main Apr 1, 2024
0 of 2 checks passed
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.

2 participants