Skip to content

"this" keyword infers type "any" instead of vue instance #1850

@ludwig801

Description

@ludwig801

Context

I am developing a project using Vue 2.6.14 version.
That being said, I have configured tsconfig's vueCompilerOptions.target to "2".

Lets say I create the following component:

<script>
export default { 
  data() { 
    return { 
      name: "Alfa" 
    } 
  }
}
</script>

Now, lets also suppose I add the "created" hook:

<script>
export default { 
  ...
  created() {
    this.name = "Beta";
  }
}
</script>

Problem

The issue arises when I type "this." in the created() hook - or any other method or computed function, for that matter - the "this" keyword is set to type "any", as opposed to the correct type which should be an extension of Vue with a string property "name".

So, type inferring is completely off. Now, I have no idea wether this is a general bug of the extension, or it is simply related to the use of the "export default" syntax, using Vue 2 syntax.

Environment

  • Volar: 0.40.13
  • Vue: 2.6.14
  • VSCode: 1.71.0
  • Typescript: 4.8.3 (in takeover mode)

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions