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

Incorrect type inference when you define slot element in v-for loop #3787

Closed
nkeyy0 opened this issue Dec 7, 2023 · 4 comments
Closed

Incorrect type inference when you define slot element in v-for loop #3787

nkeyy0 opened this issue Dec 7, 2023 · 4 comments
Labels
bug Something isn't working good reproduction ✨ This issue provides a good reproduction, we will be able to investigate it first

Comments

@nkeyy0
Copy link

nkeyy0 commented Dec 7, 2023

I'm trying to implement a table with dynamic slot names that are based on the column names, but I am faced with an issue with types in the v-for loop inside the template. For some reason the result type of the value is inferred as never, but if we do the same in the typescript we get a different type. Looks like it's an issue in the template type inferring.

Link to repro

@nkeyy0
Copy link
Author

nkeyy0 commented Dec 15, 2023

It looks like the issue is because of as operator. When I use the as operator in the defineSlots mapped type it isn't asserted to type I want to and remains the key, not cell-${key}. How can I handle such a case?

@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 Dec 16, 2023
@nkeyy0
Copy link
Author

nkeyy0 commented Dec 24, 2023

Hmm, yeah. Looks like it is. I found an issue in the TS repo related to this behavior, but looks like it can be fixed by using generics. You can find more info in this PR. And I fixed my repro according to the suggested solution in the TS PR. You can see my fix here I'm just thinking about can it be fixed directly in the Vetur, or should it be applied in the user's code?

@KermanX
Copy link
Collaborator

KermanX commented Aug 13, 2024

Assuming thatline 33 in the reproduction link has a missing [key]:

    <slot :name="`cell-${key}`" :value="tableRow[key]"></slot>
                                                ^^^^^

Then the problem is identical to this code.

Thus I think this is a TS limitation. We can't fix this on Vue's side.

@KermanX KermanX closed this as completed Aug 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working 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

3 participants