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

Volar does not takeover when type-checking .js #3192

Closed
matthew-dean opened this issue May 16, 2023 · 1 comment
Closed

Volar does not takeover when type-checking .js #3192

matthew-dean opened this issue May 16, 2023 · 1 comment

Comments

@matthew-dean
Copy link

As you know, in TypeScript, you can define a type-checked file in a few ways:

  1. With a .ts extension & tsconfig.json file for compiler settings
  2. With a .js extension & tsconfig.json with allowJs: true and checkJs: true
  3. With a .js extension & jsconfig.json with checkJs: true.
  4. With a .js extension and // @ts-check at the top of the file

This implies that a .vue file should be interpreted in "TypeScript-mode" if any of the above are true.

However, it appears that Volar / Vue language services only initiate takeover mode if a Vue tag has <script lang="ts"> or <script setup lang="ts"> IMO this is incorrect. For instance, in my setup, jsconfig.json is defined, and set to type-check all JS. I also tried adding "include": ["./lib/**/*.vue", "./lib/**/*.js"] but this had no effect.

I've defined a computed prop with JSDoc like:

computed: {
    /** @returns {[string, any][]} */
    dynamicSlots () {
      return Object.entries(this.$slots).filter(([key]) => key !== 'drag-image' && key !== 'default');
    }
  }

However, in the <template> block, it reports that dynamicSlots has a type of any. If I change the script setup to <script type="ts">, it works, but I don't think this should be necessary?

Or, is there another way to enable Vue TypeScript language services for a type-checked JS document?

@GrantGryczan
Copy link

This! Takeover mode not working in JSDoc comments not only results in this doing nothing, but it also results in an error being displayed in my editor.

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants