Vetur: Typescript: data properties not recognised in computed section

Created on 18 Oct 2019  路  6Comments  路  Source: vuejs/vetur

  • [x ] I have searched through existing issues
  • [x ] I have read through docs
  • [x ] I have read FAQ

Info

  • Platform: Win
  • Vetur version: 0.22.4
  • VS Code version: 1.39.0

Problem

Modified the Home.vue file generated using the vue cli to create a basic vue project using Typescript but not using the using the class-style vue-property-decorators. After creating a computed property Vetur complains with message

Property 'name' does not exist on type 'CombinedVueInstance>>'.

When running the component it works fine.

Reverting to Vetur version 0.18.1 also seems to fix the problem.


Reproducible Case

Most helpful comment

You need a return type annotation of the computed property.

See: https://vuejs.org/v2/guide/typescript.html#Annotating-Return-Types

All 6 comments

vetur

See screenshot for error message, and notice syntax error in the computed title.

You need a return type annotation of the computed property.

See: https://vuejs.org/v2/guide/typescript.html#Annotating-Return-Types

Thank you @ktsn

Adding a return type to the computed property fixed the problem.

I had the same problem.
Thanks for the solution @ktsn.
Make sense.

Hi @ktsn

Would you happen to know how to annotate a new variable declared in the created hook?

  created() {
    this.commentPadding = 15;
  },

I've attempted this.commentPadding: number but didn't work.

Was this page helpful?
0 / 5 - 0 ratings