question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Property does not exist on the type in vue-class-component

See original GitHub issue

I created new vue with typescript application using latest @vue/cli (v3). When I use component decorator from vue-class-component with computed/props/methods, I got an error:

Property 'count' does not exist on type 'HelloWorld'.Vetur(2339)

image

Here my code:

<script lang="ts">
import { Prop, Vue } from "vue-property-decorator";

import Component from "vue-class-component";

@Component({
  computed: {
    count() {
      return 'blabla';
    }
  }
})
export default class HelloWorld extends Vue {
  @Prop() private msg!: string;

  onClick() {
    const y = this.count;
  }
}
</script>

But according to the example it should be working fine. How do I fix this?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
ReinisVcommented, Sep 12, 2019

From the first example on the landing page image

You need to write that getter differently.

Unfortunately, decorators (as they are proposed/implemented now) cannot modify the type that they decorate, which is why nothing you ever pass to the decorator will ever show up in a typesafe manner.

And the example that you mention has a workaround added for this specific issue image

0reactions
ktsncommented, Nov 3, 2019

This is because decorator cannot change the class instance type. You have to declare the property type by yourself or use some decorator like vuex-class to map getters on class properties.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Property does not exist on the type in vue-class-component
I got an error in my TypeScript component file ...
Read more >
Property does not exist on the type in vue-class-component ...
[Solved]-Property does not exist on the type in vue-class-component-Vue.js ... If you are looking for TypeScript version, it's in the example directory.
Read more >
Vue support breaks when extending Mixin (TypeScript)
And annoyingly, a workaround I tried doesn't work either, as TS reports errors: TS2339: Property does not exist on type 'CombinedVueInstance ...>>'. import...
Read more >
TypeScript with Composition API - Vue.js
This is because Vue components are compiled in isolation and the compiler currently does not crawl imported files in order to analyze the...
Read more >
Vue + Typescript, how do I annotate this? : r/vuejs - Reddit
Property 'style' does not exist on type 'Vue'. ... I use Vue Class Component to achieve this, might be a good alternative -...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found