Skip to content

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

@darkbasic

Description

@darkbasic

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

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions