vuejs/eslint-plugin-vue

Computed properties & instance methods not recognized as already bound (`@typescript-eslint/unbound-method` false positive)

Closed this issue · 2 comments

Checklist

  • [🗸] I have tried restarting my IDE and the issue persists.
  • [🗸] I have read the FAQ and my problem is not listed.

Tell us about your environment

  • ESLint version: 9.34.0
  • eslint-plugin-vue version: 10.4.0
  • Vue version: 3.5.20
  • Node version: 22.x
  • Operating System: GNU+Linux (Fedora Silverblue 42)

eslint.config.js:

import {
  defineConfigWithVueTs,
  vueTsConfigs,
} from "@vue/eslint-config-typescript";
import { globalIgnores } from "eslint/config";
import prettierConfig from "@vue/eslint-config-prettier";
import standard from "@vue/eslint-config-standard-with-typescript";
import globals from "globals";
import tsParser from "@typescript-eslint/parser";
import vueParser from "vue-eslint-parser";
import js from "@eslint/js";
import pluginVue from "eslint-plugin-vue";
import storybook from "eslint-plugin-storybook";

export default defineConfigWithVueTs(
  globalIgnores([
    "node_modules",
    "dist/",
    "components/*/dist/",
    "**/index.d.ts",
  ]),
  js.configs.recommended,
  standard,
  storybook.configs["flat/recommended"],
  vueTsConfigs.recommendedTypeChecked,
  pluginVue.configs["flat/recommended"],
  prettierConfig,
  {
    name: "our-project/base",
    files: ["**/*.{js,jsx,ts,tsx,vue}"],
    languageOptions: {
      globals: {
        ...globals.node,
        ...globals.browser,
      },
      sourceType: "module",
      ecmaVersion: "latest",
      parser: vueParser,
      parserOptions: {
        parser: tsParser,
        projectService: true,
        sourceType: "module",
        tsconfigRootDir: import.meta.dirname,
      },
    },
    rules: {
      […]
    }
  }
);

What did you do?
Occurs when assigning to a variable or passing as a parameter to another function

  computed: {
    alwaysBound(): string {
      return "Always bound!";
    },
  },
  methods: {
    // Computed properties trigger the error
    getAlwaysBound(): string {
      const alwaysBound = this.alwaysBound; // <-- ERROR!
      return alwaysBound; 
    },
    // As do instance methods
    logAlwaysBound(): string {
      const alwaysBound = this.getAlwaysBound(); // <-- ERROR!
      console.log(this.getAlwaysBound());  // <-- ERROR!
    },

What did you expect to happen?
Vue instance methods and computed properties to be understood as already bound.

What actually happened?

Hitting this for all uses of computed properties and methods, which are all automatically bound by Vue already. Using https://github.com/vuejs/eslint-config-typescript and https://github.com/vuejs/vue-eslint-parser/ (let me know if this ticket belongs with one of those instead)

error  Avoid referencing unbound methods which may cause unintentional scoping of `this`. 
If your function does not access `this`, you can annotate it with `this: void`, or consider using an arrow function instead  @typescript-eslint/unbound-method

Repository to reproduce this issue

TBD

I'll close this issue for now since we need more information and reproduction repo to debug.

See here for causes (notably use of deprecated cache invalidation): vuejs/language-tools#5629 (reply in thread)

Obviously the code was invalid, but the error produced was not just unhelpful but misleading. Maybe not worth effort to improving, but at least any others hitting this in an overdue upgrade can find these solutions.