Skip to content

Being aware of scoped slots types based on data from parent (typescript)  #439

Description

@chojnicki

Hi. Here's simple reproduction of scoped slots implementation (of course in this form it does not make any sense, it's just to show the problem).

DemoParent.vue

<template>
  <DemoChild
    :demo-prop="x" // value "a"
    v-slot="slotProps"
  >
    {{ slotProps.item }} <- will render "a" so should be same type as demo-prop
  </DemoChild>
</template>

<script setup lang="ts">
import DemoChild from '@/components/DemoChild.vue'

type DemoPropType = 'a' | 'b'
const x: DemoPropType = 'a'
</script>

DemoChild.vue

<template>
  <div>
    <slot :item="demoProp" />
  </div>
</template>

<script setup lang="ts">
defineProps({
  demoProp: {
    type: String,
    required: true,
  },
})
</script>

It's good that extension can detect in parent component type of slotProps based on types defined inside child component, so slotProps.item as string in this example. BUT in parent I'm passing not just any string but with certain type, so I need to know that returned slot prop is also in that type.

In real world example I have universal components for table and columns and it works just great on browser but in IDE I'm losing any information of passed data types which is bad.

Any ideas for workarounds or could this be supported by extension?

Regards!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions