Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VueJS function properties referencing the data object breaks semantic highlighting #93571

Closed
jonasnordlund opened this issue Mar 27, 2020 · 4 comments
Assignees

Comments

@jonasnordlund
Copy link

jonasnordlund commented Mar 27, 2020

  • VSCode Version: 1.43.1
  • OS Version: Windows_NT x64 10.0.18363

Steps to Reproduce:

  1. In the VueJS function created, or any of your own within methods, use this code:
created: function() {
    this.name = getUserName();
    // code...
}
  1. The property name created will be highlighted as a class and conversion from a constructor function to a class will be suggested.

Workaround is to instead use this code:

created: function() {
    var self = this; 
    self.name = getUserName();
}

This issue frequently arises within VueJS models since you are meant to access the state (the data object) via this besides in special cases like when the scope has changed and you have to use a variable self as above. For example, it just happened to one of my event handlers too.

Does this issue occur when all extensions are disabled?: Yes

@octref octref removed their assignment Mar 27, 2020
@aeschli
Copy link
Contributor

aeschli commented Mar 29, 2020

Can you paste the whole file?

@jonasnordlund
Copy link
Author

jonasnordlund commented Mar 30, 2020

Here's a (complete and standalone) sample that has the problem:

var app = new Vue({
    el: '#app',
    data: {
        id: 0,
    },

    created: function() {
        this.id = 42;
    }
});

I have a feeling it's because an assignment to this is expected to happen inside a constructor function? It's just unfortunate that I have this be pretty commonplace in VueJS code where you interact with the data object so often in that way.

@aeschli
Copy link
Contributor

aeschli commented May 7, 2020

Reproduced with

const x = {
  xy: function () {
    this.id = 42;
  }
}

The appearance of a this makes typescript think this is a class.

image

@aeschli
Copy link
Contributor

aeschli commented May 7, 2020

I created aeschli/typescript-vscode-sh-plugin#15.

@aeschli aeschli closed this as completed May 7, 2020
@github-actions github-actions bot locked and limited conversation to collaborators Jun 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants