Skip to content

Base rule extension: [accessor-pairs] #9072

@paulyoung

Description

@paulyoung

Before You File a Proposal Please Confirm You Have Done The Following...

My proposal is suitable for this project

  • My proposal specifically checks TypeScript syntax, or it proposes a check that requires type information to be accurate.
  • I believe my proposal would be useful to the broader TypeScript community (meaning it is not a niche proposal).

Link to the base rule

https://eslint.org/docs/latest/rules/accessor-pairs

Description

It's possible to define a setter without a getter, and have everything type check successfully as if the getter exists.

The code in this playground errors at runtime but still type checks to due an apparent soundness issue with the type system.

The eslint/accessor-pairs rule appears to address this but it doesn't work for typescript-eslint

Fail

class MyClass {
  private _myProp: boolean = false;

  set myProp(value: boolean) {
    this._myProp = value;
  }
}

Pass

class MyClass {
  private _myProp: boolean = false;

  get myProp(): boolean {
    return this._myProp;
  }

  set myProp(value: boolean) {
    this._myProp = value;
  }
}

Additional Info

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement: new base rule extensionNew base rule extension required to handle a TS specific casefix: user errorissue was fixed by correcting the configuration / correcting the codelocked due to agePlease open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing.package: 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