"An identifier was expected causing a parsing error" triggered by v-on:change

Encountered an issue where importing a class to be used solely as a typescript type annotation resulted in a no-unused vars error. Following advice from this discussion thread, I added

"plugin:@typescript-eslint/recommended"
to the eslint config, which resolved the initial problem but led to additional parsing errors:

  • ESLint: Parsing error: Identifier expected
    appearing on v-on:change
  • ESLint: Parsing error: '}' expected.
    showing up on components: {} within @Component(...)

/App.vue:

<template>
    <div id="app" style="height: 100%">
        <input v-on:change="onChange"/> <!--This is the "Identifier expected" error -->
    </div>
</template>

<script lang="ts">
import { Component, Vue } from 'vue-property-decorator';
import Foo from "@/path/to/Foo";
import Bar from "@/path/to/Bar";

@Component({
    components: {  //This is where the `'}' expected.` error occurs
        
    }
})
export default class App extends Vue {
    onChange(e : any) : void {
        let f : Foo = Bar.baz();  //This is what caused the "no-unused-vars" problem before
        f.someFunc();
    }
}
</script>

This snippet contains my Eslint configuration specified in package.json:

"eslintConfig": {
    "root": true,
    "env": {
        "node": true
    },
    "extends": [
        "plugin:vue/essential",
        "eslint:recommended",
        "@vue/typescript",
        "plugin:@typescript-eslint/recommended"
    ],
    "parserOptions": {
        "parser": "@typescript-eslint/parser"
    },
    "rules": {}
}

Attempts were made to enable vue/valid-v-on under the rules section, along with other suggestions discussed on GitHub.

Seeking guidance on how best to address this issue.

Thank you for your help.

Edit: I have removed

plugin:@typescript-eslint/recommended"
from the eslint config and resorted to adding the line
// eslint-disable-next-line no-unused-vars
above each "unused" import in the code. This temporary solution is not ideal, hence why I am keeping the question open.

Answer №1

Update (after a year): I have encountered this issue multiple times, and I have discovered that simply restarting the TypeScript service typically resolves it.

To do this, go to the lower right corner of the IntelliJ Idea window, click on "Vue TypeScript", and then select "Restart TypeScript Service". After a brief moment, all the reported "errors" will be re-evaluated, and any incorrect markings should disappear.

This method can also help in resolving various other problems related to the TypeScript error checker.

https://i.sstatic.net/WUY6i.png

Answer №2

Recently encountered a similar issue. Initially thought it could be a simple glitch in the computer system... decided to comment out the line and rewrite it manually. Surprisingly, the compiler didn't raise any errors, so I eventually removed the original line.

Possibly just a minor bug in the system.

Answer №3

Don't parse the vue file using @typescript-eslint/parser

Create a .eslintignore file

# Skip parsing vue v-on with @typescript-eslint/parser
src/view/example/index.vue

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

When utilizing Vue3 and Vite, the error message "default is not exported by xxx" may be encountered

Not a question but a solution that may help others in the future! I recently encountered an issue while trying to migrate/build a Vue3 project with Vite. The error message I was getting was: 'default' is not exported by XXX In my case, I was dy ...

Vue.js - Ensuring that the URL domain is the same as the email domain using Vuelidate

I need to create a custom validation using Vuelidate for two input fields: url and email. The validator should check if the domain name in the url matches the domain name in the email. Valid example : url: (https://)www.mydomain.example email: <a hre ...

Tips for retrieving the text from a POST request in C#

I have a basic Angular form that allows users to upload a file along with a description. constructor(private http: HttpClient) { } upload(files) { if (files.length === 0) return; const formData: FormData = new FormData(); var filedesc ...

If a task is currently ongoing, be sure to subscribe to it; otherwise, restart it

If I have a long-running observable called longObservable, which emits a new string once after 5 seconds and then completes. longObservable(): Subject<string> { return timer(5000).pipe{ map(() => randomString()) } } Other pages c ...

Is there a way to create a type interface that points to the structure of another type?

I am focused on developing a type interface that includes properties defined in another interface. Below is the schema definition for a model object in TypeScript: export interface ModelSchema { idAttribute: string; name: string; attributes: { ...

Always deemed non-assignable but still recognized as a universal type?

I'm curious about why the never type is allowed as input in generic's extended types. For example: type Pluralize<A extends string> = `${A}s` type Working = Pluralize<'language'> // 'languages' -> Works as e ...

Tips for showing a variety of headers on your page

I am struggling to align multiple headers on the same horizontal line. Despite my efforts, only two of them display correctly while the third keeps dropping down a line. To see what I mean, take a look at this image: view current layout Here is the code ...

Running a TypeScript program that has been compiled with module resolution is not working as expected

I am currently in the process of compiling a TypeScript file with the following code: import { magic } from 'lib/magic'; magic(); The file structure looks like this: ./src/ main.ts lib/ a/magic.ts b/magic.ts Within ...

Custom HTML binding in expanding rows of Angular 2 DataTables

I am currently working on implementing a data table feature that allows for an extended child row to be displayed when clicking the + icon. This row will show additional data along with some buttons that are bound via AJAX before transitioning to Angular 2 ...

There is no 'depto_modules.length' property in this row. How should I go about fixing this issue?

I have a table set up to display data from an associated table. The functionality is working fine, but I keep seeing a warning message when I apply certain filters: The warning states that the property depto_modules.length does not exist in the row. It ad ...

Angular: How can the dropdown arrow in 'ng-select' be eliminated?

Is there a way to hide the dropdown arrow in an 'ng-select' element in Angular? <div class="col-md-6"> <ng-select id="selectServiceType" [items]="clientServiceTypes$ | async" pl ...

The click function is a member of an object within an emit event

I stumbled upon the code snippet below, which triggers the notification-alert event and passes an object as a parameter. this.$root.$emit('notification-alert', { text, type: 'warning', click: () = ...

Display the ion-button if the *ngIf condition is not present

I am working with an array of cards that contain download buttons. My goal is to hide the download button in the first div if I have already downloaded and stored the data in the database, and then display the second div. <ion-card *ngFor="let data o ...

Troubleshooting a Jasmine Unit Testing Error for Button Click in Angular 4

Exploring the world of Jasmine and Angular 4, I am aiming to write tests for a button functionality in a multi file upload feature. Below is the code snippet from my spec file: import { async, ComponentFixture, TestBed } from '@angular/co ...

A custom Typescript type for immutable values within an object

I am struggling with finding the right data type for my function, where I need to work with static types. I have experimented with Type, interface, class, Record, and others, but none seem to fit perfectly. GEOLOCATIONS is a constant record that maps cou ...

React with Typescript - cannot be expressed as a function

I am currently exploring ReactJS and Typescript. While trying to authenticate a user using the methods below, I encountered the following error message: Unhandled Rejection (TypeError): auth.authenticate is not a function onSubmit src/components/Login/ind ...

Understanding Typings in Typescript

Just delving into the world of Angular2 and finding it quite exciting, but running into a roadblock with Typings. The concept is not clear to me - how do I utilize them and what purpose do they serve? Different sources suggest different approaches, some me ...

Angular - Conceal Protected Links on the Template

In my AuthGuard, I have implemented CanActivate which returns either true or false based on custom logic: import { Injectable } from '@angular/core'; import { Router, CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular ...

Guide to incorporating Bootstrap and its dependencies into a Chrome extension powered by Vue using npm

As I delve into the world of webpack, vue, and vuex to create a chrome extension, I encountered an issue with loading Bootstrap 4 within the extension. Despite using the correct path for the node modules folder, I keep getting a file not found error when t ...

What could be causing Heroku to display Babel-loader and Vue-loader errors during the deployment of my MEVN app?

I've encountered difficulties deploying my MEVN application on Heroku. Despite researching the error, I couldn't find a solution. As someone new to webpack and Heroku, I need assistance. My Vue project was created using vue init webpack client. T ...