Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[unbound-method] Should prevent conforming to a bound-style interface method with an unbound method #3503

Open
Labels
accepting prsGo ahead, send a pull request that resolves this issueenhancement: plugin rule optionNew rule option for an existing eslint-plugin rulepackage: eslint-pluginIssues related to @typescript-eslint/eslint-plugin
@jtbandes

Description

@jtbandes
  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.
  • I haveread the FAQ and my problem is not listed.

Repro

interfaceFoo{unbound():number;unboundOk(this:void):number;bound:()=>number;}functionwhat(f:Foo){constunbound=f.unbound;// lint error 👍constunboundOk=f.unboundOk;// no error 👍constbound=f.bound;// no error 👍// console.log(unbound());  // runtime error (expected)console.log(unboundOk());// runtime error ❌console.log(bound());// runtime error ❌}classExampleimplementsFoo{x=3;unbound(){returnthis.x;}unboundOk(){returnthis.x;}// no error 👎 (TypeScript issue rather than typescript-eslint issue?)bound(){returnthis.x;}// no error 👎 (this issue)}what(newExample());

eslint config:https://github.com/foxglove/eslint-plugin/blob/main/configs/typescript.js
tsconfig:https://github.com/foxglove/studio/blob/main/packages/tsconfig/tsconfig.base.json

Expected Result

class Example implements Foo is problematic. There should be an error onbound() { return this.x } when is used to satisfy the interface requirementbound: () => number;.

Actual Result

The lint rule does not reject this incorrect method implementation, which leads to a runtime error.

Versions

packageversion
@typescript-eslint/eslint-plugin4.26.0
@typescript-eslint/parser4.26.0
TypeScript4.3.2
ESLint7.27.0
node15.9.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    accepting prsGo ahead, send a pull request that resolves this issueenhancement: plugin rule optionNew rule option for an existing eslint-plugin rulepackage: 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


      [8]ページ先頭

      ©2009-2025 Movatter.jp