Content-Length: 320988 | pFad | https://github.com/typescript-eslint/typescript-eslint/issues/1056#issuecomment-2562979820

96 Bug: [prefer-readonly] autofixer doesn't add type to property that is mutated in the constructor · Issue #1056 · typescript-eslint/typescript-eslint · GitHub
Skip to content

Bug: [prefer-readonly] autofixer doesn't add type to property that is mutated in the constructor #1056

@JounQin

Description

@JounQin

Repro

{
  "rules": {
    "@typescript-eslint/prefer-readonly": 2
  }
}
// your repro code case
class X {
  private _isValid? = true;
  get isValid(): boolean {
    return this._isValid;
  }

  constructor(data?: {}) {
    if (!data) {
      this._isValid = false;
    }
  }
}

Expected Result

No report

Actual Result

@typescript-eslint/prefer-readonly

Member '_isValid' is never reassigned; mark it as `readonly`

Versions

package version
@typescript-eslint/eslint-plugin 2.3.3
@typescript-eslint/parser 2.3.3
TypeScript 3.6.3
ESLint 6.5.1
node 12.11.1
yarn 1.19.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    accepting prsGo ahead, send a pull request that resolves this issuebugSomething isn't workinglocked 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

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions









      ApplySandwichStrip

      pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


      --- a PPN by Garber Painting Akron. With Image Size Reduction included!

      Fetched URL: https://github.com/typescript-eslint/typescript-eslint/issues/1056#issuecomment-2562979820

      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy