Skip to content

[unbound-method] false negative when destructuring a method #2198

Closed
@hgezim

Description

@hgezim

Repro

{
  "rules": {
    
    "@typescript-eslint/no-explicit-any": "off",
    "@typescript-eslint/no-unused-vars": "off",
    "@typescript-eslint/no-inferrable-types": "off",
    "@typescript-eslint/naming-convention": [
      "error",
      { "selector": "variableLike", "format": ["camelCase", "UPPER_CASE", "PascalCase"], "leadingUnderscore": "allow" },
    ],
    "@typescript-eslint/unbound-method": ["error"],
  }
}
class MyClass {
    public log(): void {
        console.log(this);
    }
}

const instance = new MyClass();

// This logs the global scope (`window`/`global`), not the class instance
const myLog = instance.log;
myLog();

// This log might later be called with an incorrect scope
const { log } = instance;

log()

Expected Result
const { log } = instance; to show error.

Actual Result
const { log } = instance; doesn't show any errors.

const myLog = instance.log; does error as expected.

Additional Info

Versions

package version
@typescript-eslint/eslint-plugin 3.2.0
@typescript-eslint/parser 3.2.0
TypeScript 3.9.5
ESLint 7.2.0
node 11.15.0
npm 6.7.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingduplicateThis issue or pull request already existspackage: 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