Skip to content

[unbound-method] Support super.foo in constructor #1866

@markfields

Description

@markfields

Repro

{
  "rules": {
    "@typescript-eslint/unbound-method": [
            "error",
            {
                "ignoreStatic": true
            }
        ]
  }
}
class BaseClass {
    x: number = 42;
    logThis() { console.log(`x is ${this?.x}`); }
}

class OtherClass extends BaseClass {
    superLogThis: any;
    constructor() {
        super();
        this.superLogThis = super.logThis;  // X - Incorrect eslint error
    }
}

const oc = new OtherClass();
oc.superLogThis();  // Works despite eslint error in constructor

Expected Result
No unbound-method error. In the test case above, oc.superLogThis() correctly prints x is 42.

Actual Result
unbound-method error about super.logThis in OtherClass's constructor.

Additional Info

Versions

package version
@typescript-eslint/eslint-plugin 2.17.0
@typescript-eslint/parser 2.17.0
TypeScript 3.7.5
ESLint 6.8.0
node 10.19.0
npm 6.13.4

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghas prthere is a PR raised to close thispackage: 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