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

Using unions in defineProps in conjunction with withDefaults breaks emits type inference #12110

Open
darkbasic opened this issue Oct 4, 2024 · 2 comments
Labels
language-tools related to vue language-tools scope: types

Comments

@darkbasic
Copy link

Vue version

3.5.11

Link to minimal reproduction

https://play.vuejs.org/#eNqNVNtu00AQ/ZWRX5JIkaOq9MVyArQECSRKBbxhhIw9TrbsTbtrN1Hqf2d2NwlO1FZ989zOnJk5613yXuu0azHJktxWhmkHFl2rgZdyNS8SZ4tkUUgmtDIObpTQ0BglYJTOvOFLR4XMZ7GWMslwKDQvHZIFkIcaxxxHghPb8FUk4LbaO2Qr/qAhO+tK3nrPFRnvxHbZoXRkjnEC8wXsenLPCDGfDeCTKRGslGzYKr23StIUO9+0SCrqyjiar9oxJWmIDELEx0rO1cPn4HOmxenBX62x+vuE/95uvK9I7gxaNB3RP8ZcaVboYnj5/RY39H0MClW3ftgXgt/QKt56jjHtupU10R7kBbafwv6ZXP2wy41DaQ9DeaI+sw/5RUL38At/bvT/dC/TN6GukD1t8XDL18lgBw/MrT9gU7bc2SnU2DCJd0bpo7EUzFno92KJKqF66dA0ZYVwXVq8KU0diiK/oIwMrDM0p3cwuuzbgwMeQbacE91ToNsgIA8FtF+UtX0Sm9SWwSiqjagABLllhBn0d4760ZSV394rcZt9+hD5MEdA9nkQwOZDxo8njXwijWwd6NBhfrLm8WDLuU9fjCfTyMIvilhYJdCtqSnR6CenA32JDyrmy1KcE4x9ka5GbQcnzEPB/jlm8JPq9lC/qJIovPz4a9aFDwi/juCaRd/5O/7dofGqJgVeplfpxUXS/wMjZpcD

Steps to reproduce

The SFC Playground is a bit broken because even if you remove withDefaults it still won't be able to infer the type if you hover on the emit with your mouse. So I suggest to copy paste the code locally: vscode will be able to infer the event type once you remove withDefaults.

Alternatively you can try to assign the event to a function which expects a different type and run vue-tsc --build --force.
Without withDefaults it will complain about the mismatch:
image

If you leave withDefaults it won't complain because he thinks the inferred type is any:
image

What is expected?

Using withDefaults in conjuction with union props shouldn't break emits type inference.

What is actually happening?

Using withDefaults in conjuction with union props breaks emits type inference.

This is without withDefaults:
image

While this is with withDefaults:
image

System Info

System:
    OS: Linux 6.10 Arch Linux
    CPU: (16) x64 AMD Ryzen 9 PRO 7940HS w/ Radeon 780M Graphics
    Memory: 26.39 GB / 58.64 GB
    Container: Yes
    Shell: 5.2.37 - /bin/bash
  Binaries:
    Node: 20.17.0 - /run/user/1000/fnm_multishells/57865_1728023771872/bin/node
    Yarn: 4.5.0 - /run/user/1000/fnm_multishells/57865_1728023771872/bin/yarn
    npm: 10.8.2 - /run/user/1000/fnm_multishells/57865_1728023771872/bin/npm
    Watchman: 20240414.112832.0 - /usr/bin/watchman
  Browsers:
    Chromium: 129.0.6668.89
  npmPackages:
    vue: ^3.5.11 => 3.5.11

Any additional comments?

No response

@KazariEX
Copy link
Contributor

KazariEX commented Oct 5, 2024

Solution in #12012 (comment)

@KazariEX
Copy link
Contributor

KazariEX commented Nov 2, 2024

Workaround: #12012 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
language-tools related to vue language-tools scope: types
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants