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

vue/tsc-2.2.0 breaks emit parameters inference when using withDefaults with union props #5112

Open
darkbasic opened this issue Jan 7, 2025 · 1 comment
Labels
bug Something isn't working upstream: core

Comments

@darkbasic
Copy link

darkbasic commented Jan 7, 2025

Vue - Official extension or vue-tsc version

2.2.0

VSCode version

1.96.2

Vue version

3.5.13

TypeScript version

5.6.3

System Info

System:
    OS: Linux 6.12 Arch Linux
    CPU: (16) x64 AMD Ryzen 9 PRO 7940HS w/ Radeon 780M Graphics
    Memory: 29.42 GB / 54.70 GB
    Container: Yes
    Shell: 5.2.37 - /bin/bash
  Binaries:
    Node: 20.17.0 - /run/user/1000/fnm_multishells/3839_1736234935335/bin/node
    Yarn: 4.6.0 - /run/user/1000/fnm_multishells/3839_1736234935335/bin/yarn
    npm: 10.8.2 - /run/user/1000/fnm_multishells/3839_1736234935335/bin/npm
    Watchman: 20240414.112832.0 - /usr/bin/watchman
  Browsers:
    Chromium: 131.0.6778.204

package.json dependencies

No response

Steps to reproduce

Since I've upgrade from vue-tsc 2.1.10 to 2.2.0 it stopped inferring emit parameters whenever I am using withDefaults with union props:

image

DISCLAIMER: withDefaults + union props is already heavily broken and I already had to use the following workaround:

const saneProps = computed<typeof props>(() => {
  if ('contextId' in props && props.contextId == null) {
    const { contextId, ...rest } = props
    return rest as typeof props
  } else if ('contextId' in props && props.requestId == null) {
    const { requestId, ...rest } = props
    return rest as typeof props
  } else {
    throwError('If this gets triggered vue fixed withDefaults and saneProps can be removed')
  }
})

The reason is that withDefaults sets the union props to undefined even if you don't provide them in withDefaults's second parameter, thus breaking 'contextId' in props/'requestId' in props (which always returns true for both).

I've linked a repro but it doesn't work on the playground, so you should copy/paste the code locally.

What is expected?

Correctly infers emit param types

What is actually happening?

Doesn't infer emit param types

Link to minimal reproduction

https://play.vuejs.org/#eNqNU01z0zAQ/Ss7OtB0pmMf4JRxAwUCEw7QAW6Ig2tvXBVZEvpIwhT/966kxEmaTqe+2Nrdp3373vqeXRlTrAKyKatcY4Xx4NAHA7JW3SVn3nE240r0RlsPn4R1HpZW93BWlOkUwWdcVWVGUy0dPPZG1h7pBFBllMW/AZ1ftHRrzRmUlKzKg0p2Qd0arZaiK+6cVkTpPuI5a3RvhET7zXihFTGaQsrEXC2lXn9JMW8DXuzizS02f56I37lNjHF2bdGhXSFnY87XtkOf0/MfX3FD32Oy122QVP1M8js6LUPkmMveB9US7YO6xHaRxBSq++nmG4/K7YaKRGPlkOo5I2k/PDP6nu7r4k3CcTWQihHzAk9bXAqF8154V6U767adwi9BllATqKfgvCWWMPyme2eT8yOXH3ncitXsqirj69TWcVFetmWR/7hku2Fox7haC3/7EZd1kN5NYt88w7XVxlVZlq06AJ3VwSzat7sxcnyAV5CQ8fm/r44P7Z4nWxekggr9DRk3JknZJyHjUh93OYCQagAkXrJ0i91SiytS3zScbb07FvhE4qhExr8jp+Jf5P6pBiYK15/jhedwOYsz0A5iIXW3T+QOpz/c8ADATkw/

Any additional comments?

No response

@KazariEX
Copy link
Collaborator

KazariEX commented Jan 7, 2025

It's a core issue.

image

@KazariEX KazariEX added bug Something isn't working upstream: core and removed pending triage labels Jan 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working upstream: core
Projects
None yet
Development

No branches or pull requests

2 participants