Difficulty encountered when implementing decorators in VueJS with TypeScript

Encountering a strange issue while creating a new app using vue-cli: the HelloWorld component is throwing an error with decorators, despite not making any changes as all code and configurations are from vue-cli.

Here is the specific error message:

ERROR in /Users/JohnSmith/test/src/components/HelloWorld.vue
37:1 Unable to resolve signature of class decorator when called as an expression.
  Type '<VC extends VueClass<Vue>>(target: VC) => VC' is missing the following properties from type 'typeof HelloWorld': extend, nextTick, set, delete, and 7 more.
    35 | import { Component, Prop, Vue } from 'vue-property-decorator';
    36 | 
  > 37 | @Component
       | ^
    38 | export default class HelloWorld extends Vue {
    39 |   @Prop() private msg!: string;
    40 | }

A workaround was discovered:

@Component({
  props: {
    msg: {type: String},
  },
})
export default class HelloWorld extends Vue {
  // @Prop() private msg!: string;
}

The goal is to use decorators without errors in the generated dummy project.

Environment setup:

  • macOS High Sierra 10.13.6
  • node v11.3.0 (with brew)
  • npm 6.4.1
  • yarn 1.12.3 (with brew)
  • Vue CLI v3.2.1
  • brew doctor is fine

Vue-cli options used for project creation:

? Please pick a preset: Manually select features
? Check the features needed for your project: Babel, TS, PWA, Router, Vuex, CSS Pre-processors, Linter
? Use class-style component syntax? Yes
? Use Babel alongside TypeScript for auto-detected polyfills? Yes
? Use history mode for router? (Requires proper server setup for index fallback in production) Yes
? Pick a CSS pre-processor (PostCSS, Autoprefixer and CSS Modules are supported by default): Sass/SCSS
? Pick a linter / formatter config: TSLint
? Pick additional lint features: (Press <space> to select, <a> to toggle all, <i> to invert selection)Lint on save
? Where do you prefer placing config for Babel, PostCSS, ESLint, etc.? In dedicated config files
? Save this as a preset for future projects? No

No information found regarding this particular issue.

Any insights on the source of the problem would be greatly appreciated.

Thank you for your assistance!

Answer №1

If you want to bring in Vue from vue library, you can do it this way:

import Vue from 'vue';
@Component
export default class Greetings extends Vue {
  @Prop() private message!: string;
}

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

Vue struggles to handle data coming from a composable function

For my specific case, I need to verify whether the user has subscribed to my product through both Stripe and Firebase. To accomplish this, I created a composable function that checks for the current subscription in the Firebase collection. If the user cur ...

Does Angular 1.3.x have a corresponding .d.ts file available?

Is there a .d.ts file available for Angular 1.3.x to assist in transitioning an app to Typescript 2.0? ...

Having difficulty choosing an item from a personalized autocomplete search bar in my Vue.js/Vuetify.js project

NOTE: I have opted not to use v-autocomplete or v-combobox due to their limitations in meeting my specific requirements. I'm facing difficulties while setting up an autocomplete search bar. The search functionality works perfectly except for one mino ...

Tips on extracting value from a pending promise in a mongoose model when using model.findOne()

I am facing an issue: I am unable to resolve a promise when needed. The queries are executed correctly with this code snippet. I am using NestJs for this project and need it to return a user object. Here is what I have tried so far: private async findUserB ...

Verify the legitimacy of the object

I'm encountering an issue while attempting to create a function that verifies the validity of an object. const isPeriodValid = (period: Period | null): boolean => { return period && period.start && period.end; } export interfac ...

Encountering an Error: Unforeseen Token < Causing Webpack Configuration Problem in Typescript

Seeking assistance to resolve an issue that has arisen while working on a project with Typescript, React, and Webpack. I referred to the guide available at https://www.typescriptlang.org/docs/handbook/react-&-webpack.html After configuring everything, ...

What could be causing the sluggish performance of my wysiwyg editor in Vue.js?

I've been exploring the use of a wysiwyg editor on my webpage. Implementing simple two-way data binding with v-model="text" and straightforwardly outputting <div v-html="text"></div>. As a beginner in vuejs, I have encountered a performanc ...

Is there a way to access the history of Vue routers?

I am looking for a way to determine if the Vue router has additional entries in its history that can be navigated back to. This information is crucial for deciding whether or not to execute the exit app function. The app should only navigate back to prev ...

Here's a unique version: "Exploring the process of retrieving data in Laravel using

I am facing an issue while trying to submit data using axios and Vue to Laravel. The problem is that the submission does not seem to work as expected. My goal is to retrieve the data from a textarea, convert it to uppercase using ucfirst function in Larave ...

Issue with FontAwesome icon selection in Vue2 (nuxt) not displaying icons

If you're looking for the icon picker, you can find it here: https://github.com/laistomazz/font-awesome-picker I've tried running it, but unfortunately, the icons are not showing up. When I inspect the elements, the code is there but the icon is ...

Utilizing Fullcalendar with Vuex

Since fullcalendar updated their props to go outside of the <FullCalendar /> element, I've been experiencing difficulties when it comes to rendering events. I have confirmed that the state request is being fulfilled in Vuex through various test ...

What is the correct way to utilize environment variables in TypeScript?

I am currently working on creating a basic API using TypeScript. However, I have encountered an issue where whenever I utilize an environment variable, the TS compiler throws an error indicating that it could be undefined. For example: // Not Working con ...

Include a new module in the declarations NgModule utilizing ts-morph

Currently, I am utilizing the ts-morph library and my objective is to add a new component to the declarations: This is my initial setup: @NgModule({ declarations: [], imports: [], providers: [], }) Here is what I am aiming for: @NgModule({ declarations: [ ...

Cypress automation script fails to trigger Knockout computed subscription

Within my setup, I have implemented two textboxes and a span to display the result. Date: <input data-bind="value: dateValue"/> Number: <input data-bind="value: dateValue"/> Result : <span data-bind="text: calculatedValue">Result Should ...

Stop allowing the firing of the button click event when the Enter key is pressed in

Currently, I am faced with a user interface issue where pressing the enter key in an input field seems to be triggering a click event on a button (probably because it now has focus). Even though the button has a prevent modifier on its click action (<bu ...

Timed up 10-second countdown with vue.js

<html> <head> <meta charset="utf-8" /> <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment.min.js" ></script> <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script> < ...

What is the best way to make an attribute in an interface mandatory only when another attribute is set to true

How can a relative be made required only when another attribute is true? For Example: interface ITesteProps { required: boolean content{!required && '?'}: string } I understand that this code is not valid. Is it possible to make the ...

Re-subscribe to an Observable that has been unsubscribed in RxJS

Utilizing a Service to periodically "ping" my server every 2.5 seconds, I am able to retrieve the response time from the server by using observables. My implementation also involves angular 2 and typescript. Now, I am facing an issue where I want to be a ...

Importing components with local data within an ngFor in Angular TypeScript

Having recently started working with Angular2, I am facing a challenge with importing components in ngFor loops. The issue seems to arise when importing components with data in ngFor loops; it checks for values in the .ts file instead of the local variabl ...

Add a trash can or delete icon within every row of a table using Vue.js

I am new to vue.js and I'm struggling to implement a trash icon in each row of a table for deleting rows. Additionally, I'm trying to make the input of a cell act as a dropdown menu or list within the table rows. I recently came across this scrip ...