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

Configuration: automatic type acquisition for vue.js #44289

Closed
francoisromain opened this issue Feb 23, 2018 · 12 comments
Closed

Configuration: automatic type acquisition for vue.js #44289

francoisromain opened this issue Feb 23, 2018 · 12 comments
Assignees
Labels
*question Issue represents a question, should be posted to StackOverflow (VS Code)

Comments

@francoisromain
Copy link

  • VSCode Version: 1.20.1
  • OS Version: 10.13.3

Hello,
I configured vs code for automatic type acquisition in a javascript / vue.js project (not typescript). This is handy most of the time, but this also shows errors on non-errors:

  • on computed properties mapped from vuex. Example: Property 'isLoaded' does not exist on type '() => any'. any.
  • on refs. Example: this.$refs.name.focus() makes the error: Property 'focus' does not exist on type 'Vue | Element | Vue[] | Element[]'.

jsconfig.json:

{
  "compilerOptions": {
    "checkJs": true,
    "target": "es2017"
  },
  "exclude": ["node_modules", "**/node_modules/*", "dist", "example/dist"]
}

Is there a way to avoid showing those non-errors as errors?

Thank you

@vscodebot vscodebot bot added the javascript JavaScript support issues label Feb 23, 2018
@mjbvz
Copy link
Collaborator

mjbvz commented Feb 23, 2018

@francoisromain Can you please share some example code where these errors are showing up

@francoisromain
Copy link
Author

@mjbvz sure.

<template>
<div><input type="text" ref="name"></div>
</template>
<script>
  mounted () {
      this.$refs.name.focus()
  }
</script>

this makes an error on .focus(): Property 'focus' does not exist on type 'Vue | Element | Vue[] | Element[]'.

I am trying to reduce an example about the computed property error and come back quick.

@octref
Copy link
Contributor

octref commented Feb 23, 2018

By ATA you mean you don't have Vue with typing installed in your project folder and want Vetur to work with it?

@francoisromain
Copy link
Author

francoisromain commented Feb 23, 2018

Sorry I am new to this. Am I suppose to install vue with typing? (I thought type declaration files were automatically downloaded).

I have Vetur installed and running, I am not sure to understand how Vetur and ATA split the type checking work. Do you mind explaining a bit please? Thank you

@octref
Copy link
Contributor

octref commented Mar 8, 2018

When you install vue, you get the typing out of the box.

The problem is caused by having "checkJs": true in your jsconfig, and Vue's typing for $refs seems to be a bit off. I'll open an issue for Vue side soon.

@HerringtonDarkholme
Copy link

HerringtonDarkholme commented Mar 9, 2018

Hi, $refs indeed contain Element or Vue instances. So you don't have focus method on $refs' element. The problem is you have to cast it to the correct subtype.
microsoft/TypeScript#17453

You can also try turning checkJS off.

@octref octref added *question Issue represents a question, should be posted to StackOverflow (VS Code) and removed javascript JavaScript support issues labels Mar 9, 2018
@vscodebot
Copy link

vscodebot bot commented Mar 9, 2018

Please ask your question on StackOverflow. We have a great community over there. They have already answered thousands of questions and are happy to answer yours as well. See also our issue reporting guidelines.

Happy Coding!

@vscodebot vscodebot bot closed this as completed Mar 9, 2018
@francoisromain
Copy link
Author

@HerringtonDarkholme @octref
How do you "cast it to the correct subtype"?

@octref
Copy link
Contributor

octref commented Mar 9, 2018

      /** @type {HTMLElement} */ (this.$refs.name).focus();

@francoisromain
Copy link
Author

@HerringtonDarkholme @octref
thank you!

@francoisromain
Copy link
Author

@octref
Copy link
Contributor

octref commented Mar 10, 2018

Not really. Those seem to be js/ts errors. You should open a new issue.

@vscodebot vscodebot bot locked and limited conversation to collaborators Apr 23, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
*question Issue represents a question, should be posted to StackOverflow (VS Code)
Projects
None yet
Development

No branches or pull requests

4 participants