Open
Description
Vue version
^5.0
Link to minimal reproduction
Steps to reproduce
- 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>
- Define a default slot, with the generic as a slot prop.
E.g.
defineSlots<{
default (props: {
item: T,
}): any
}>()
- In a component use
defineSlots
to define props with a discriminated union.
E.g.
defineProps<(
| { someProp: false }
| { someProp: true }
)>()
- Declare a variable that fits the prop of the first component, with an additional property.
E.g.
const items = [{
id: 1,
somePropertyNotInThePropDefinition: 'foo'
}]
- 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.