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

[class-literal-property-style] Literal property style does not respect inherited types #3602

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

Description

@Paril
  • 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

{"rules": {"@typescript-eslint/class-literal-property-style":"warn"  }}
abstractclassBaseClass{// class-literal-property-style error; this one is fair, because it isn't entirely aware// that I'm going to override it, so this one I can see just being an eslint disablegetcursor():string|string[]{return'crosshair';}readonlyhidden:boolean=false;abstractgeticon():string;}classChildClassextendsBaseClass{// class-literal-property-style error// this one, however, is interesting because it should know that it is// overriding an existing getter and can't be made a literaloverridegetcursor(){return'square';}readonlyhidden:boolean=truereadonlyicon='circle'something:boolean}

Expected Result

ESLint shouldn't suggestclass-literal-property-style when overriding a getter, because it is not possible to turn an inherited getter into a readonly property (ts(2610))

Actual Result

It suggests breaking the code by attempting to convert the children into a literal when it is not possible. Conversely, it suggests converting the base class one into a literal, which will not work for children that need to use a getter for conditional return values (ts(2611)).

Additional Info

As a side-issue, this rule is not enum-aware and does not trigger if the literal returned from a getter is an enum value:

enumTest{Value}classTestClass{// should trigger heregettest(){returnTest.Value;}}

Versions

packageversion
@typescript-eslint/eslint-plugin8.2.1
@typescript-eslint/parser8.2.1
TypeScript4.3.4
ESLint7.28.0
node14.8.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 rulelocked 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


      [8]ページ先頭

      ©2009-2025 Movatter.jp