vuejs / language-tools

⚡ High-performance Vue language tooling based-on Volar.js
https://marketplace.visualstudio.com/items?itemName=Vue.volar
MIT License
5.87k stars 407 forks source link

Cannot recognize custom components and show error #4841

Closed GnaugGnay closed 2 months ago

GnaugGnay commented 2 months ago

Vue - Official extension or vue-tsc version

Vue - Official extension

VSCode version

1.93.0

Vue version

2(with vue-class-component)

TypeScript version

3.9.10

System Info

System:
    OS: macOS 11.6
    CPU: (4) x64 Intel(R) Core(TM) i5-7500 CPU @ 3.40GHz
    Memory: 9.70 GB / 32.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 14.17.6 - /usr/local/bin/node
    Yarn: 1.22.21 - /usr/local/bin/yarn
    npm: 6.14.15 - /usr/local/bin/npm
  Browsers:
    Chrome: 128.0.6613.137
    Safari: 14.1.2

package.json dependencies

{
  devDependencies: {
    "vue-class-component": "7.2.6"
  }
}

Steps to reproduce

  1. open a vue sfc file of my project;
  2. check custom component in template tag.

What is expected?

shows normal with the tag of custom component.

What is actually happening?

shows error with every tag of the custom component.

errors look like: XXX does not exist on type 'Required<{} & __VLS_WithComponent .... ts-plugin(2339).

Link to minimal reproduction

No response

Any additional comments?

it happends when I update the extension to version 2.1.x, and disappears using version 2.0.x.

截屏2024-09-11 下午4 49 22
KazariEX commented 2 months ago

Could you provide a minimal reproduction for it?

GnaugGnay commented 2 months ago

@KazariEX here is a demo for you

截屏2024-09-11 下午5 37 48
KazariEX commented 2 months ago

This is a known limitation, we deliberately do not support decorators to avoid overly complex code. However, since I don't know if it can obtain the correct type (or any) before 2.1, I don't know how to fix it.

GnaugGnay commented 2 months ago

@KazariEX I think, you guys should at least provide an option like "suppressTemplateIndexError" for us old-vue-version users. I really appreciate your works on it, but this error lints almost drive me crazy.

KazariEX commented 2 months ago

How about skipTemplateCodegen?

GnaugGnay commented 2 months ago

@KazariEX Better name than mine!

KazariEX commented 2 months ago

This is an existing feature, you can configure it in your tsconfig.json:

"vueCompilerOptions": {
    "skipTemplateCodegen": true
}
KazariEX commented 2 months ago

Could you tell me if using components imported with decorators in template before 2.1 can obtain the correct types?

GnaugGnay commented 2 months ago

Could you tell me if using components imported with decorators in template before 2.1 can obtain the correct types?

The answer is No. I thought it's a limitation of vue2 or whatever at the first time and ignore this inconvenience.

As for the "skipTemplateCodegen" option, I have tried it and turns out it brings more disadvantages. e.g., I can no longer using cmd + mouseLeft in template to locate the defination of variables and functions.

KazariEX commented 2 months ago

The answer is No. I thought it's a limitation of vue2 or whatever at the first time and ignore this inconvenience.

This is what I want to know, If we just infer it as unknown, fixing it will become easier.

GnaugGnay commented 2 months ago

Seems like our opinions finally come up together, hope ur update as soon as posible. I have to use version 2.0.x for a while.