Skip to content
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

Version 2: looping over slots as a variable causes error TS2345 #4025

Closed
isazulay opened this issue Mar 6, 2024 · 6 comments
Closed

Version 2: looping over slots as a variable causes error TS2345 #4025

isazulay opened this issue Mar 6, 2024 · 6 comments
Labels
design limitation good reproduction ✨ This issue provides a good reproduction, we will be able to investigate it first

Comments

@isazulay
Copy link

isazulay commented Mar 6, 2024

Use case:
Having a wrapper component, I want the parent to be able to populate the slots of the wrapped component.

Implementation:

<template>
  <v-alert
    v-bind="props"
    variant="outlined">
    <template v-for="(_, slot) in slots" #[slot]="scope">
      <slot :name="slot" v-bind="scope || {}" />
    </template>
  </v-alert>
</template>

<script setup lang="ts">
import type { VAlert } from 'vuetify/components/VAlert';
import type { Props } from './types/CustomAlert.model';

const props = defineProps<Props>();
const slots = defineSlots<VAlert['$slots']>();
</script>

Current behavior:
The use case is still possible to run with the same code prior to v2 of vue-tsc, but running the vue-tsc command return the following error:

error TS2345: Argument of type '{ props?: Record<string, any> | undefined; }' is not assignable to parameter of type '{ props: Record<string, any>; }'.
  Types of property 'props' are incompatible.
    Type 'Record<string, any> | undefined' is not assignable to type 'Record<string, any>'.
      Type 'undefined' is not assignable to type 'Record<string, any>'.

Expected behavior:
Running vue-tsc should not throw an error.

@so1ve so1ve added bug Something isn't working good reproduction ✨ This issue provides a good reproduction, we will be able to investigate it first labels Mar 6, 2024
@so1ve
Copy link
Member

so1ve commented Mar 6, 2024

Could you please provide a reproduction without using vuetify's types? Thanks in advance.

@isazulay
Copy link
Author

isazulay commented Mar 6, 2024

Can be closed. Not reproduce without import Vuetify types

@isazulay isazulay closed this as not planned Won't fix, can't repro, duplicate, stale Mar 6, 2024
@so1ve so1ve reopened this Mar 7, 2024
@so1ve
Copy link
Member

so1ve commented Mar 7, 2024

Sorry I don't mean that. I mean you can copy and simplify vuetify's types and inline them to this SFC. Anyway I'll debug locally.

@isazulay
Copy link
Author

isazulay commented Mar 7, 2024

I think the bug is in the implementation of slot types in Vuetify. I'm not able to reproduce it when implementing a similar model to the one from Vuetify, because then the scope property within #[slot]="..." is typed. When using the Vuetify component this is set to any and only throws an error on build time. When using my own component, it throws the error in the IDE.

@webdevnerdstuff
Copy link

I'm also experiencing this as well. In the npm package vue-tsc v2.0.26 (and lower) the error did not happen. It only started as of v2.0.28.

@webdevnerdstuff
Copy link

I think the bug is in the implementation of slot types in Vuetify. I'm not able to reproduce it when implementing a similar model to the one from Vuetify, because then the scope property within #[slot]="..." is typed. When using the Vuetify component this is set to any and only throws an error on build time. When using my own component, it throws the error in the IDE.

Would you please check out this issue which also seems to address this problem that keeps coming and going.
vuejs/core#575 (comment)

@KazariEX KazariEX removed the bug Something isn't working label Jan 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
design limitation good reproduction ✨ This issue provides a good reproduction, we will be able to investigate it first
Projects
None yet
Development

No branches or pull requests

5 participants