#21155·eslint

Bug: [prefer-arrow-callback] invalid report on a function expression with a TS `this` parameter

Author: bradzacherCreated Jul 27, 2026Updated Sep 28, 2026
Labelsbugrepro:yesStale

Environment

ESLint Playground

What parser are you using?

@typescript-eslint/parser

What did you do?

Playground Code

javascript
/*eslint prefer-arrow-callback: ["error"]*/

function acceptsCb(cb) {}

class Foo {}

acceptsCb(function (this: Foo) {})

ESLint Configuration

Tap to see full config
javascript
import { defineConfig } from "eslint/config";
import tsParser from "@typescript-eslint/parser";

export default defineConfig([
    {
        "languageOptions": {
            "parserOptions": {
                "ecmaFeatures": {
                    "jsx": true
                }
            },
            "parser": tsParser
        }
    }
]);

ESLint Output

7:11 Unexpected function expression. (prefer-arrow-callback)

What did you expect to happen?

No report because arrow functions cannot define a this: T parameter. The autofix creates broken code by fixing the line to acceptsCb((this: Foo) => {}) which is a TS semantic error and a syntax error in most TS parsers.

The rule should ignore function expressions that define a TS this: T parameter.

What actually happened?

7:11 Unexpected function expression. (prefer-arrow-callback)

Link to Minimal Reproducible Example

https://eslint.org/play/#eyJ0ZXh0IjoiLyplc2xpbnQgcHJlZmVyLWFycm93LWNhbGxiYWNrOiBbXCJlcnJvclwiXSovXG5cbmZ1bmN0aW9uIGFjY2VwdHNDYihjYikge31cblxuY2xhc3MgRm9vIHt9XG5cbmFjY2VwdHNDYihmdW5jdGlvbiAodGhpczogRm9vKSB7fSlcbiIsIm9wdGlvbnMiOnsicnVsZXMiOnt9LCJsYW5ndWFnZU9wdGlvbnMiOnsicGFyc2VyT3B0aW9ucyI6eyJlY21hRmVhdHVyZXMiOnsianN4Ijp0cnVlfX0sInBhcnNlciI6IkB0eXBlc2NyaXB0LWVzbGludC9wYXJzZXIifX19

Participation

  • I am willing to submit a pull request for this issue.

AI acknowledgment

  • I did not use AI to generate this issue report.
  • (If the above is not checked) I have reviewed the AI-generated content before submitting.

Additional comments

No response