vuejs / core

🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
https://vuejs.org/
MIT License
47.68k stars 8.33k forks source link

The `EmitsToProps ` typescript utils does not properly retain the function type declarion for emits option. #11470

Open shenjunjian opened 3 months ago

shenjunjian commented 3 months ago

Vue version

3.4.30

Link to minimal reproduction

https://play.vuejs.org/#eNp9U8uO2zAM/BVClzwQ2If2lDpB220KtEAf6BY96eLadFYbmRL0SFME+fdScuzNAsWeLHE4wyEpn8U7a4tjRLEWlW+csgE8hmhB17TfSBG8FFtJqrfGBTiDww4u0DnTw4xpswn6gL35FXGApCjKFCgSXRJIqspBnbX4ErC3ug7IN4BqpIa/FjezGcDb5oGrI5eXIt2Ubg75sq2yLCczsypvZMSKrTaGOrUvHr0h7uecxKVoTG+VRvfNBmWI/awhIwmrtTZ/PudYcBFXY7x5wObwn/ijP6WYFN8denRHlGLCQu32GAZ4d/8VT3yewN60UXP2C+AP9EbH5HFIex+pZds3edntpzxuRfuffncKSH5sKhlNmZecLwVv5+6F1p/svipeZ56kC0/xujae37TzFjtFWcwQUhj3n0tI8SZtFE85lzPrqPP3ljHPVbFXwU8OyuUSOuWwBUPQaNUc+LgsBzDf520d6jVQ7H+jWwEe1/DFRI+7I0suRh3gJxmio9w/e0kRbmWcg3XGPi/quS+NGZjqpZfHSdfvfXA836vAQMJUE2r/nGboLj/UJ+rHSE2a9a2F/D/NJ8NXu/PFZktR62w5zX6RTuLyDz2BKoA=

Steps to reproduce

In my vscode, create a vue typescript project , pnpm create vite && pnpm i then copy the code from above playground , I cannot see type declaration on click when I mouse on it

image

What is expected?

export default defineComponent({
  emits: {
    /** fired on clicked */
    click(data: number, ev: MouseEvent) {
      return true;
    }
  }
...............
}

will generate the demo.d.ts as below

Readonly<import('vue').ExtractPropTypes<{
    /** simple prop */
    type: {
        type: StringConstructor;
    };
    /** event as prop */
    onChange: {
        type: FunctionConstructor;
    };
}>> & {
    onClick?: ((data: number, ev: MouseEvent) => any) | undefined;
},

I expect that before onClick line , it comes with type declaration------/* fired on clicked /

What is actually happening?

As in the screenshot, the is no intellisense on click

I think it's easy to fix. I'm locating the problem below: (https://github.com/vuejs/core/blob/0b8ba6320eaf8b08e83d7c1e1309254dd0b021da/packages/runtime-core/src/componentEmits.ts#L40)

image

System Info

No response

Any additional comments?

No response

shenjunjian commented 3 months ago

another minimal reproduction:

https://play.vuejs.org/#eNp9VMluGkEQ/ZVKX1gEM4fkRAAlcYiUSFkUWzn1ZTxTQJue6lEvGAvx76nuWYwlywgx0/VqffWas/jcNNkxoFiIpSutajw49KEBXdBuJYV3Uqwlqbox1sMZLG7hAltrahhx2GiAvmJt/gVsISmyPBqyGC4J+Fsach6qFeFj7zueSGIkz6E2wSH/HhEMAeHJg1aEjtEqM3SjVXkA/rCr3yuXQNCGEyryqLVySJzAq6aP2HP7mA7+qeEXScu8nY+n4YPHutGFRz4BLN/N56/10FjTOJjPW6d+wphwNRoBfCpTFWZJinhSujykw3qZpmdnjlzmV7XEjBllKrZqlz04Q0z7OSaXojR1ozTa341XTJUUC0hIxAqtzeOPZPM24Ky3l3ssD6/YH9wp2qT4Y9GhPaIUA+YLu0PfwpvbXzzmFVibKmj2fgP8i87oEHts3b4EqrjtK7/U7fekCkW7O7c5ed5OP1RsNHpekr8ULKKbN0Z/bvd99iHFSbowi526mL9BmhVuWRYxmSEk38s0lZDiY1w7npIvexZBp+d1xDhVxVp5N3SQT6ewVRarKIoy6hCrGcDdHl9KD7bGsjZZlVGaZUFkPNwjVMrx7p84XlHCu/uWwTRvK6Sk46rwxQIo1PdoZ4DHBfyMetwcua9J3wzw9fPBciImkQeKFuajJzPJ9UXnjsnRmIChXpQvO3XPW295SV2CNghjTShcCpuBMzUPlJRedVhLyJCxv27PWb8FKuMur7tLfyvjYZZukvFktaagdZom7nYS38TlP4nQhUY=