Skip to content

Generic slot props in loops with discriminated union props definition breaks slot prop type #12012

Open
@cathrinevaage

Description

@cathrinevaage

Vue version

^5.0

Link to minimal reproduction

https://play.vuejs.org/#eNqVVNtq20AQ/ZVBL7EhkSlpoQgl0Eso6UMaGpc+ZENR5ZGzqTQrdleug6t/78yu5Zhiu8mTds/czpyZ1Sp517bposMkS3JXWt16UATg0HdtONUFzc9U4p1KFJ0r0k1rrIcPhr+E5L9rf/+NtKFra1oHlTUNHKWTPXYpdaQon8RanI8vHpu2LjzyDSDfl9mZBk9aPsKEHfPJVlRyzPxKQ5Wepw/OEDezklwqKTmZrtF+aT0n4h4yCBaxFXVtfn8OmLcdHg94eY/lrx34g1sKppJriw7tAlWysfnCztFH88XNFS75vDE2ZtbV7H3A+BWdqTvhGN3edzRj2lt+ge1lEF/TfOoulh7JDU0JUfHsg79KWGbRcV/rT3RP09chTlHPKh6Y2tOCbPbjuevxCQmtLm9q43fvx5bDekEUzbDShKF8PpJKf2AVdkCgDKqidii0/zWIEoKPz0djycNr4Txo3hYHZ3AbJNCzDF4FpYY4tP7xyvjL0O9HKa1FtQyOKmOYT3/3gqXdaicKnoXyLFP4ilKCLk4cezC6CvSYdDCEhACriKb/YQh90CDfK+iOt3JI++eMGWAegxiZAq8z0szxEERW6pqfaGMvXG17ilF6USCD6e0d69+vZxS9hMLai4Giqz2M5L2z+3pxJZhjw+T6cQYFPQ5JDg1HZB4kr4xl1iPJNAZNkc8wkTCn9ZgitutX82OBVh4eS3WavknfJv1fZJPSBA==

Steps to reproduce

  1. In a component, define a generic type, and use it as the array type for a prop.
    E.g.
<script
  setup
  lang="ts"
  generic="T extends { id: number }"
>
defineProps<{
  items: T[],
}>()
</script>
  1. Define a default slot, with the generic as a slot prop.
    E.g.
defineSlots<{
  default (props: {
    item: T,
  }): any
}>()
  1. In a component use defineSlots to define props with a discriminated union.
    E.g.
defineProps<(
  | { someProp: false }
  | { someProp: true }
)>()
  1. Declare a variable that fits the prop of the first component, with an additional property.
    E.g.
const items = [{
  id: 1,
  somePropertyNotInThePropDefinition: 'foo'
}]
  1. Use the first component in the template, with the variable as the prop, and use the v-slot directive so that the slot prop is available. Inside the slot body, access the additional property.
    E.g.
<ComponentWithGenericSlot
  :items="items"
  v-slot="{ item }"
>
  {{ item.somePropertyNotInThePropDefinition }}
</ComponentWithGenericSlot>

What is expected?

The additional property should be typed correctly with the additional property in the slot prop.

What is actually happening?

The additional property is not recognized. The type of the slot prop is the type of the generic, and nothing else.

System Info

System:
    OS: macOS 15.0
    CPU: (8) arm64 Apple M1
    Memory: 50.31 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.17.0 - /usr/local/bin/node
    Yarn: 1.22.19 - /opt/homebrew/bin/yarn
    npm: 10.8.2 - /usr/local/bin/npm
    pnpm: 7.33.7 - /opt/homebrew/bin/pnpm
    bun: 1.0.14 - /opt/homebrew/bin/bun
  Browsers:
    Safari: 18.0
  npmPackages:
    vue: ^3.5.0 => 3.5.8

Any additional comments?

This started with Vue 5.5. Changing the typescript or vue-tsc versions doesn't affect this.

Curiously, in my local project, when using vue-tsc, wrapping the defineProp in an empty withDefaults was required to produce the described behaviour. This is not the case in the play.vuejs.org editor.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions