Skip to content

Bug: prefer-return-this-type report and fixes code to one with TS errors #11225

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
4 tasks done
Lightning00Blade opened this issue May 16, 2025 · 0 comments
Open
4 tasks done
Labels
bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for team members to take a look

Comments

@Lightning00Blade
Copy link

Before You File a Bug Report Please Confirm You Have Done The Following...

  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.
  • I have searched for related issues and found none that matched my issue.
  • I have read the FAQ and my problem is not listed.

Playground Link

https://typescript-eslint.io/play/#ts=5.8.2&fileType=.tsx&code=MYGwhgzhAEBCkFNoG8BQ1oEsIAlMBN8EA7ALmgCMB7KkBMY6AXmgBcAnAVwQG51oImCiEzEA5uXgQkAH2jFOIEM3mKQfDADMAFAEpJiaHIVKU-DJk3RtAQlYALbADpseQiV1mM36OwStOdkYHbA1vAF9zX39A4McIJ0FhUTEwyMjUUEgYAGUEYCpifC8sXAIiMkoaOgYVDm4wpJFxcjyCoqNVUxYTdX4dfTZ4zt6SiytbEITXco8x7z8AoKHQqMifRdiVhKaUtNRwoA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6Y6RAM0Wls-yxoTWvgAWlZKJKJ0UXtAD20SODABfEOqA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA&tokens=false

Repro Code

class Base {
  isHidden: boolean = true;
  sibling: Base | null = null;
  f(): Base | null {
    if (!this.isHidden) {
      return this;
    }
    return this.sibling;
  }
}

class Second {
  isHidden: boolean = true;
  sibling: Second | null = null;
  f(): this | null {
    if (!this.isHidden) {
      return this;
    }
    return this.sibling;
  }
}

ESLint Config

module.exports = {
  parser: "@typescript-eslint/parser",
  rules: {
    "@typescript-eslint/prefer-return-this-type": "error"
  },
};

tsconfig

{
  "compilerOptions": {
    // ...
  }
}

Expected Result

The code is marked as valid

Actual Result

EsLint report an error, after fixer is applied TypeScript shows an error.

Additional Info

No response

@Lightning00Blade Lightning00Blade added bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for team members to take a look labels May 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for team members to take a look
Projects
None yet
Development

No branches or pull requests

1 participant