An error occurred due to an unexpected token found in the JsonForms custom-renderer props

I found inspiration in an example from this website to develop a custom renderer for JsonForms using Vue:

However, as I implement this example in my .vue file within the script tags, I encounter an error UnexpectedToken right after declaring the props. It happens immediately after the generic type definition and the brackets for the parameters (the function has no parameters).

This is the TypeScript code snippet I am working with:

<script lang="ts">
  import { ControlElement } from '@jsonforms/core';
  import { RendererProps, rendererProps, useJsonFormsControl } from '@jsonforms/vue';
  import { defineComponent } from 'vue';

  import { rankWith, scopeEndsWith, JsonFormsRendererRegistryEntry } from '@jsonforms/core';

  const CustomCheckboxRenderer = defineComponent({
    name: 'custom-checkbox-renderer',
    props: {
      ...rendererProps<ControlElement>(), <---- The error occurs on this line right after the >
    },
    emits: ['input'],
    setup(props: RendererProps<ControlElement>) {
      return useJsonFormsControl(props);
    },
    methods:{
      onChange(event: Event){
        this.handleChange(this.control.path, (event.target as HTMLInputElement).checked);
      }
    }
  });
  export default CustomCheckboxRenderer;

  export const entry: JsonFormsRendererRegistryEntry = {
    renderer: CustomCheckboxRenderer,
    tester: rankWith(3, scopeEndsWith('tter')),
}
</script>

Here is the error message I received:

ERROR in [eslint]
C:\Projects\GH\app\src\renderers\MyCheckboxRenderer.vue
  26:39  error  Parsing error: Unexpected token (11:39)

✖ 1 problem (1 error, 0 warnings)

I suspect it could be an issue with the eslint configuration. I have tried using different parsers, but it leads to problems in other parts of my project. Below is my eslint configuration:

module.exports = {
  root: true,
  env: {
    node: true
  },
  'extends': [
    'plugin:vue/vue3-essential',
    'eslint:recommended'
  ],
  parserOptions: {
    parser: '@babel/eslint-parser'
  },
  rules: {
    'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
    'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off'
  }
}

Answer №1

If you're working with Typescript, you'll definitely need to utilize a custom parser. Check out this resource: @typescript-eslint/parser

For a specific example from eslint.vue, take a look at: how to use a custom eslint parser?

parserOptions: {
  parser: '@typescript-eslint/parser'
},

For further clarification on the distinction between parser and parseOption.parser, I suggest delving into this discussion on Stack Overflow: the difference between parser and parseOption.parser

Answer №2

After some investigation, I successfully pinpointed the problem.

The project where this occurred initially had Vue configured for JavaScript only.

To address this, I utilized the Vue CLI to incorporate TypeScript by executing vue add typescript. After resolving several associated errors, the Vue component was able to compile without any issues.

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

What is the best way to transfer information from a vue-resource function to the visual layer of a vue component?

Within my resource.js file, I have an ES6 class that is exported: import Vue from 'vue' import VueResource from 'vue-resource' Vue.use(VueResource) export class Resource { getMovies () { // GET /someUrl return Vue.http.g ...

There seems to be a problem with the [at-loader] node_modules@typesjasmine

My webpack build suddenly started failing with no package updates. I believe a minor version change is causing this issue, but I'm unsure how to resolve it. Can someone provide guidance on what steps to take? ERROR in [at-loader] node_modules\@t ...

What is the best way to assign default values when destructuring interfaces within interfaces in TypeScript?

My goal here is to create a function that can be used with or without arguments. If arguments are provided, it should work with those values; if not, default values should be used. The issue I'm facing is that although there are no TypeScript errors ...

Troubleshooting parameter issues with Vue Router on page refresh

Why does the parameter work when I'm directed from a `router-link' to a component, but then not work when I refresh the page? Let me explain: routes.js has the following paths: { path: '/myspaces', name: 'myspaces', ...

Discover a method to deselect a checkbox within a separate component in angular15

I am currently dealing with Angular15 and I find myself stuck on an issue related to checkbox selection change. Situation: As per the requirements, I have a menu bar and a Checkbox. The Checkbox is generated from a reusable component which is used in the ...

Deciding on the optimal times to implement data structure methods within Vue.js applications

Currently studying the Vue.js v2 documentation and I'm noticing a difference in how data is structured. When looking at the official documentation, they demonstrate creating data like this: var data = { a: 1 } var vm = new Vue({ el: '#example&a ...

Exploring the wonders of using the Async Pipe with Reactive Extensions

I'm facing a little issue with the async pipe in Angular. Here's my scenario: I need to execute nested observables using the async pipe in HTML because I'm utilizing the on-push change detection strategy and would like to avoid workarounds ...

Set the enumeration value to a variable

I am facing a problem where it seems impossible to do this, and I need help with finding a solution enum Vehicles { BMW='BMW', TOYOTA='Toyota' } class MyVehicles { public vehicleName: typeof Vehicles =Vehicles; } const veh ...

Is there a way to calculate the total of form field values in Vue.js?

I am currently working on a project that involves calculating the total sum of 5 input fields. I have set up data fields and v-model for each field, and in my computed section I am attempting to calculate the sum. <input type="text" class="form-contro ...

Is it possible to change the transition behavior within a Vue component?

Is there a way to modify or replace transitions within a Vue component? I am currently using Buefy components for my website, but I have encountered an issue with certain components like collapse that have a slot with a fade transition that I do not pref ...

Does Vue trigger v-bind when referring to a component?

My upload component is set up to submit after a message has been sent. Within this component, there is an action that specifies the request URL using v-bind. However, I've noticed that whenever I try to access the reference, the v-bind does not seem t ...

Incorrect deduction of the argument type for a higher-order function

If I wanted to create a function that takes an object of type T and another value, where the type P should somehow be restricted by T (for example, P should be an array of keys of T), I could easily write it like this: function customFunction<T, P exte ...

Tips for setting a data-attribute on the body tag using the current route name in Vue

I have been considering adding a data-attribute to the body of my vue-app that would display the current route's name. I prefer not to utilize the vue-body-class package and want to keep it simple. Currently, I am implementing this in each of my main ...

Updating non-data properties dynamically in a custom AG Grid cell renderer

In my grid setup, I have implemented an editor button in a column for each row and a new item creator button outside the grid. One of the requirements is that all buttons should be disabled when either the create or edit button is clicked. To achieve thi ...

Error Message: Angular Unit Test Fails with "Cannot read property 'subscribe' of undefined"In this article, we will

My Angular app's unit tests using Jest are giving me the error "TypeError: Cannot read property 'subscribe' of undefined". Despite searching online, none of the solutions provided seem to work for me. Below is some relevant code: page-view. ...

Updating the background color using typescript

Before transitioning to angular development, I had experience working with vanilla Javascript. I encountered a challenge when trying to modify the css properties of specific elements using Typescript. Unfortunately, the traditional approach used in Javascr ...

The selected check icon does not appear in the console log

Objective: Display preselected data from selected checkbox in console.log Issue: The preselected data is not appearing in the console log. When manually checked, the data shows up. What am I missing? About Me: I am a beginner in Angular. Thank ...

Error in Angular 2: Component unable to locate imported module

I'm facing an issue where a module I want to use in my application cannot be found. The error message I receive is: GET http://product-admin.dev/node_modules/angular2-toaster/ 404 (Not Found) The module was installed via NPM and its Github reposito ...

Creating Typescript types based on the values of other props: A guide

Can the TypeScript prop type be dynamically changed based on the runtime value of another prop? For instance type MyComponent = { propA: boolean | string propB: typeof propA boolean ? number : string } Is it feasible to determine the prop type of p ...

What is the process of extending a class in TypeScript?

I have a few services that contain the same code: constructor (private http: Http) { //use XHR object let _build = (<any> http)._backend._browserXHR.build; (<any> http)._backend._browserXHR.build = () => { let _xhr = _ ...