-
-
Notifications
You must be signed in to change notification settings - Fork 446
fix(language-core): prevent eager inference of slot props from generics #5247
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
Conversation
vue-component-meta
vue-component-type-helpers
@vue/language-plugin-pug
@vue/language-server
@vue/language-service
@vue/language-core
vue-tsc
@vue/typescript-plugin
commit: |
is this fix available in 2.2.8 already? thanks! |
@targetlucked69 It was included in the |
@KazariEX When will v3.0.0 be released? I'm having trouble. |
@KazariEX sorry for the ping, I've been following this for quite a bit hoping to find a fix myself but I'm getting more and more lost. Over Nuxt UI I'm trying to fix a type utility to dynamically type slot names. The developer passes an array to the component, where each item may have its own slot name and depending on the component it might also have one or multiple suffix to that slot name (eg: I tried to mimic as much as possible the implementation from this PR, but I'm still getting error:
The following is the smallest reproduction I was able to make (I'm interested in the <script lang="ts">
interface TestItem {
label: string
slot?: string
}
interface TestProps<T extends TestItem> {
items: T[]
}
type DynamicSlots<
T extends { slot?: string },
S extends string | undefined = undefined,
D extends object = {}
> = {
[K in (T['slot'] & string | `${T['slot'] & string}-${S & string}`)]: (props: {
item: Extract<T, { slot: S extends undefined
? K
: K extends `${infer Base}-${S & string}`
? Base
: K }>
} & D) => any
}
type TestSlots<T extends TestItem> = {
'item': (props: { item: T, index: number }) => any
'item-trailing': (props: { item: T, index: number }) => any
} & DynamicSlots<T, 'trailing', { index: number }>
</script>
<script setup lang="ts" generic="T extends TestItem">
defineProps<TestProps<T>>()
defineSlots<TestSlots<T>>()
</script>
<template>
<div v-for="(item, index) of $props.items" :key="index">
<span>
<slot
:name="((item.slot ? item.slot : 'item') as keyof TestSlots<T>)"
:item="item"
:index="index"
/>
<slot
:name="((item.slot ? `${item.slot}-trailing` : 'item-trailing') as keyof TestSlots<T>)"
:item="item"
:index="index"
/>
</span>
</div>
</template> |
@sandros94 How did you solve this problem? |
I'm not sure I have resolved it tbh, but I realized that I was getting those typecheck errors only in the local docs and not playgrounds, so there might be an issue on our end. And considering it is the first time I debug vue-tsc I tend to think about me doing something wrong. If you have some free time I would gladly take any advice and much appreciated if you could take a look at that example I've made 🙏 |
you mean this extension? Could I ask a link to docs or a bit of guidance on how to correctly debug it and access its virtual code?
You mean that it is not possible to pick that specific slot? Sorry, I might be missing the meaning of some terminology like "calling slots" |
fix #5228, fix #5246