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

Bug: [no-misused-promises] Fails to check unions that contain misused promises. #8494

Closed
4 tasks done
kirkwaiblinger opened this issue Feb 16, 2024 · 0 comments · Fixed by #8534
Closed
4 tasks done
Labels
accepting prs Go ahead, send a pull request that resolves this issue bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@kirkwaiblinger
Copy link
Member

Before You File a Bug Report Please Confirm You Have Done The Following...

  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.
  • I have searched for related issues and found none that matched my issue.
  • I have read the FAQ and my problem is not listed.

Playground Link

https://typescript-eslint.io/play/#ts=4.8.4&showAST=es&fileType=.tsx&code=CYUwxgNghgTiAEAzArgOzAFwJYHtXyjDBAAcMBnANRy2AGEoIIAjQgawAoA3G%2Bxl9gC54aUIiyoQweAB94HDgEp4AXgB88HrUWKA3AFgAUKEiwEYPOQzwAtlACezEAAUYOG1nIgGTVmDbCoiDiktJyCsrq8K7uniAAPFrAaopGhMRkVLw%2BAv4cdo4ubh5eOX5sekA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6Jge1oFtLlZkiACa1i0Dr0GoMkRNHHRI4MAF8QKoA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA&tokens=false

Repro Code

declare function acceptsVoidCallback(voidCallback: undefined | (() => void));
declare const maybePromiseCallback: undefined | (() => Promise<void>)
acceptsVoidCallback(maybePromiseCallback);

ESLint Config

module.exports = {
  "rules": {
    "@typescript-eslint/no-misused-promises": "error"
  }
}

tsconfig

{
  "compilerOptions": {
    "strictNullChecks": true
  }
}

Expected Result

I expect that the 3rd line should report "Promise returned in function argument where a void return was expected"

Actual Result

There was no error on the 3rd line.

Additional Info

This continues the conversation from #5744 (comment).

The rule does already check arguments that have multiple call signatures, but it doesn't check whether it is a union of something that has call signatures and something that doesn't.

We should also try to ensure that complex test cases around (possibly multiple) spread args behave appropriately, including yucky things like

declare function acceptsVoidCallbacks(...voidCallbacks: Array<undefined | (() => void)>);
declare const maybePromiseCallback: undefined | (() => Promise<void>)
declare const voidCallback: () => void;
acceptsVoidCallbacks(voidCallback, undefined, ...[voidCallback, voidCallback], ...[maybePromiseCallback], ...[voidCallback]);
@kirkwaiblinger kirkwaiblinger added bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for maintainers to take a look labels Feb 16, 2024
@bradzacher bradzacher added accepting prs Go ahead, send a pull request that resolves this issue and removed triage Waiting for maintainers to take a look labels Feb 20, 2024
yeonjuan added a commit to yeonjuan/typescript-eslint that referenced this issue Feb 22, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepting prs Go ahead, send a pull request that resolves this issue bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants