Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

<Transition> does not support :key binding when use v-for #8682

Closed
KawaiiZapic opened this issue Jul 1, 2023 · 7 comments
Closed

<Transition> does not support :key binding when use v-for #8682

KawaiiZapic opened this issue Jul 1, 2023 · 7 comments

Comments

@KawaiiZapic
Copy link

KawaiiZapic commented Jul 1, 2023

Vue version

3.3.4

Link to minimal reproduction

https://stackblitz.com/edit/vitejs-vite-xcl8cd

Steps to reproduce

<template>
  <transition v-for="i in 5" :key="i">
    {{ i }}
  </transition>
</template>

Run vue-tsc

What is expected?

Type check is passed.

What is actually happening?

error TS2345: Argument of type '{ key: number; }' is not assignable to parameter of type 'TransitionProps'.
  Object literal may only specify known properties, and 'key' does not exist in type 'TransitionProps'.

2   <transition v-for="i in 5" :key="i">
                               ~~~~

System Info

No response

Any additional comments?

Only <Transition> has this problem, <TransitionGroup> work fine

@WXperia
Copy link

WXperia commented Jul 1, 2023

use transition-group

@KawaiiZapic
Copy link
Author

KawaiiZapic commented Jul 1, 2023

use transition-group

What if:

<script>
const list=[{
  id:0,
  type: "user"
}]
</script>
<template>
  <transition v-for=item in list :key=item.id :name="'transition-'+item.type"/>
</template>

@auvred
Copy link
Contributor

auvred commented Jul 1, 2023

It seems to be related to vuejs/language-tools#3340

Transition component is functional, I guess that this is what causes the error

export const Transition: FunctionalComponent<TransitionProps> = (
props,
{ slots }
) => h(BaseTransition, resolveTransitionProps(props), slots)

@LinusBorg
Copy link
Member

Closing this here as its about the language tools

@KawaiiZapic
Copy link
Author

KawaiiZapic commented Jul 2, 2023

Closing this here as its about the language tools

I don't think it is a language tools problem.
this is caused by bad type definition in core, we need modify the type definition of FunctionalComponent to inherit some Vue-reserved props like :key

@LinusBorg LinusBorg reopened this Jul 2, 2023
@VytenisSidabras
Copy link

Faced this issue when updating an existing project to a Typescript setup so can add a few additional details:

  • This error is not related to v-for as you get it without using them.
  • TransitionProps does not inherit key prop, so it throws TS error that for the moment can be ignored with @vue-ignore
  • Transitions with added :ref still work and render things properly.

@yyx990803
Copy link
Member

This is a language tools issue - the error is no longer reproducible with latest versions of Vue and vue-tsc.

@github-actions github-actions bot locked and limited conversation to collaborators Nov 24, 2023
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants