-
-
Notifications
You must be signed in to change notification settings - Fork 593
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
v-slot with { } accept slot data has type any error in typescript project when update to 0.27.2 #2258
Comments
In 0.28.0, I don't see it being reported as error, but it is still unable to infer the type from the child component. Is this expected? |
Yes, we can't infer type from slot. |
It definitely enhances the Typescript development experience if we have this feature. It should be one of the reasons why people would rather use Typescript over Javascript when using VueJs. Hope to see this implemented in the future (not just avoiding this). |
It's a lot of work. |
If you know ahead of time something takes a lot of work, then you just implied you know the direction towards the end goal, just think about how to achieve it while your Typescript skill gets better. |
Follow vuejs/rfcs#192 |
@yoyo930021 I see there is work in progress regarding this issue. I'm using Vuetify and have the slot type issue with its virtual scroller. Is there any workaround to manually type hint the correct slot type from "any"? I didn't find a way for that. Wondering if it's currently even possible (just manual hinting). |
I use small life hack for it in my TypeScript + Vue3 + ESLint components: <template>
<Modal>
<template #footer="{footerMessage, close}: SlotProps">
<p>{{ footerMessage }} <a href="#" @click.prevent="close">Dismiss</a></p>
</template>
</Modal>
</template>
<script setup lang="ts">
import Modal from './Modal.vue'
// close function signature
type VoidCallback = () => void
// it used for typing slot props
// eslint-disable-next-line no-unused-vars
interface SlotProps {
footerMessage: string
close: VoidCallback
}
</script> The main idea to define interface for typing slot props. |
Did not help for me. I managed with: <template #expansion-row="props: any">
<span> More about {{ props.item.username }} </span>
</template> |
Please use volar instead of vetur for vue setup and slot type support. |
Info
Problem
when update to 0.27.2
use v-slot with { } to accept data has this error tip,but I don‘t know how to definition this type
and when use 0.27.1 version has no this error tip
Reproducible Case
The text was updated successfully, but these errors were encountered: