[Vuejs]-Eslint flagging the first function definition in a Vue file

3👍

Are you sure you’ve configured ESLint for TypeScript?
The error suggests it is expecting JavaScript, and types and other TS features, are not valid JS.


You need to use @typescript-eslint in your eslint config file.

For example, in .eslintrc.json (or .eslintrc, or in YAML format), use something similar to:

{
  "root": true,
  "parser": "@typescript-eslint/parser",
  "plugins": [
    "@typescript-eslint"
  ],
  "extends": [
    "eslint:recommended",
    "plugin:@typescript-eslint/eslint-recommended",
    "plugin:@typescript-eslint/recommended",
    "@vue/typescript/recommended"
  ]
}

And ensure you’ve got the required libraries installed:

yarn add -D eslint @typescript-eslint/parser @typescript-eslint/eslint-plugin @vue/typescript/recommended

(@typescript-eslint/parser is the parser, @typescript-eslint/eslint-plugin contains some standard linting rules for TS, @vue/typescript/recommended is the Vue specific rules, and ofc eslint is the core ESLint library.)

Leave a comment