Skip to content

Bug: [unbound-method] Inconsistent behavior for reporting union types with unbound methods #11683

@ronami

Description

@ronami

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.9.2&showAST=es&fileType=.tsx&code=MYGwhgzhAEBiD29oG8BQ1oCMwC8cAoBKFaAX1XNVEhgCEwAnFdLXHaAXmgEYBuC1KgAmAU2oMR0YPAB2EAC7QAZogBccRP1HjJ0uYoCuMgJaz1CJAB9o9Bv1QB6B9DDQIxgLYAHELsiTjGGkGCWB5EABPaAkveAZ5ESEAGix4eQALFxgPEQ9MESYRAA8vCShTGUdnMBkhLOh4TAArMUUvMHkEhhlVKlkFVKMhbk5lRAA6bDx%2BPQHkVjx1THghgCYyUZV4eydoYxkXaCMKlNlIhubW6HbOgoPA6JFY%2BMSUgHd0419oHLyCl2AwBEUCqewgMgA5PJerNFMshgBmUbHWSTNgzfqKeZTHBLFa1AAsGy4KJk-CAA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6WJgIwHsOATWgFtE%2BABbc%2B6KImjRu0SODABfEMqA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA&tokens=false

Repro Code

class Foo {
  bazz() { }
}

class Bar {
  bazz = 1;
}

declare const foo: Foo;
declare const union: Foo | Bar;

// a simple case is correctly reported, both as member expression
// and as object pattern:
const bound1 = foo.bazz;
const { bazz: bound2 } = foo;

// in a union, only object pattern is reported, while member access
// isn't:
const bound3 = union.bazz;
const { bazz: bound4 } = union;

ESLint Config

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

tsconfig

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

Expected Result

I expected the rule to have consistent behavior in how it reports union types with unbound methods, as I think there's no difference between using ObjectPattern or MemberExpression for creating an unbound method.

Actual Result

The rule didn't report the unbound method created from a MemberExpression of a union type.

Additional Info

No response

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

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions