vuejs / language-tools

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

when both emit and model defined, plus import emit type from another file, component loses type #4824

Open RayGuo-ergou opened 2 months ago

RayGuo-ergou commented 2 months ago

Vue - Official extension or vue-tsc version

2.1.6

VSCode version

none

Vue version

3.5.3

TypeScript version

5.5.4

System Info

System:
    OS: Linux 5.15 Ubuntu 22.04.4 LTS 22.04.4 LTS (Jammy Jellyfish)
    CPU: (16) x64 AMD Ryzen 7 7800X3D 8-Core Processor
    Memory: 40.29 GB / 46.66 GB
    Container: Yes
    Shell: 5.8.1 - /usr/bin/zsh
  Binaries:
    Node: 20.17.0 - ~/.n/bin/node
    npm: 10.8.2 - ~/.n/bin/npm
    pnpm: 9.9.0 - ~/.n/bin/pnpm
    bun: 1.0.26 - ~/.bun/bin/bun

package.json dependencies

No response

Steps to reproduce

To reproduce, these requirement has to meet

  1. Define emits
  2. Define model
  3. The emit type extends radix-vue's type

Then the component inside template will have type of unknown.

Should be able to reproduce with the repo provided below. Here's some screenshots

image image image image

What is expected?

Having correct type for components.

What is actually happening?

Infer as unknown

Link to minimal reproduction

https://github.com/RayGuo-ergou/volar-reproduction

Any additional comments?

possible related to https://github.com/vuejs/language-tools/issues/4822 ?

Also the current radix-vue is built with 2.0.x so this might caused this issue?

RayGuo-ergou commented 2 months ago

image Type union is okay

image Interface extends is not

RayGuo-ergou commented 2 months ago

Found another issue, if params passed into defineModel, the params type of emits will be unknown [] image image

KazariEX commented 2 months ago

Could the fix #4823 solve this?

RayGuo-ergou commented 2 months ago

Potentially yes, I will report back once it's merged and released.

RayGuo-ergou commented 1 week ago

FYI @KazariEX #4823 does not fix this.

KazariEX commented 1 week ago

image

KazariEX commented 1 week ago

The prop and event names generated by defineModel are determined only by the first parameter, passing checked will result in duplication with the update:checked event that comes with the component library.

RayGuo-ergou commented 3 days ago

But I did not pass 'checked' to defineModel's name 🤔

https://github.com/RayGuo-ergou/volar-reproduction/blob/main/src/components/Checkbox.vue#L23

const checked = defineModel<boolean>();

or I misunderstood?