Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Bug: [unbound-method] Reword message to better explain this: void binding #10056

@JoshuaKGoldberg

Description

@JoshuaKGoldberg

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=5.5.2&fileType=.tsx&code=MYewdgzgLgBA3jAhgIxAJ1gXxgXhmAUwHcYBBVDAYXCjRABt6C0AKASgG4AoLldKdhyA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6WJgIwHsOATWgFtE%2BABbc%2B6KImjRu0SODABfEMqA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA&tokens=false

Repro Code

const { abort } = new AbortController();

abort();

ESLint Config

module.exports = {
  "rules": {
    "@typescript-eslint/unbound-method": "error"
  }
}

tsconfig

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

Expected Result

The error message should tell me what's wrong, and optionally give a hint as to how I can fix it. If the type comes from a .d.ts outside of my control -say, node_modules/ or lib.*.d.ts- then there's no need to suggest changes to the type signature such as annotating with this: void.

Actual Result

Avoid referencing unbound methods which may cause unintentional scoping of `this`.
If your function does not access `this`, you can annotate it with `this: void`, or consider using an arrow function instead. 

Additional Info

Maybe we just remove the "If your ... annotate it with this: void" from the error?

Avoid referencing unbound methods which may cause unintentional scoping of `this`.
Consider using an arrow function instead. 

Thanks @mattpocock for accidentally reminding me to file this, I'd been meaning to for a while. 😄 https://x.com/JoshuaKGoldberg/status/1838944653401375048

💖

Metadata

Metadata

Assignees

No one assigned

    Labels

    accepting prsGo ahead, send a pull request that resolves this issuebugSomething isn't workingpackage: eslint-pluginIssues related to @typescript-eslint/eslint-plugin

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions