Closed Kruptein closed 6 months ago
Vue template AST doesn't provide key binding from ForNode so we can't fix it yet.
Sorry for posting a duplicate!
How can I tell Volar to ignore an issue in a template?
@bartenra you can use _index
instead of index
as variable name.
Vue template AST doesn't provide key binding from ForNode so we can't fix it yet.
Is there any changes about this issue in the last year ? Thanks
@Zehir unfortunately we have nothing can do here, you can open an issue in vue/core repo.
This actually nowadays works properly in my setup. Unsure if I should close the issue or not given that apparently Zehir still has issues.
By using a _ prefix to your variables names ?
No, with the proper names.
I just tested the following quickly:
<div v-for="[i, layer] of layers" :key="i">
{{ layer }}
</div>
and this does not complain. If I remove the key section it properly complains that i
is not used.
I have 2 project, in one of them I don't have the issue.
What is the type definition of layers
?
In this case an array of strings.
ComputedRef<LayerName[]>
to be precise, with LayerName being a string enum
I just tested the following quickly:
<div v-for="[i, layer] of layers" :key="i"> {{ layer }} </div>
This problem is only happen with <template>
tag but not html element / component tag.
This problem is only happen with
<template>
tag but not html element / component tag.
Aaah right, my bad, the initial PR is quite a while ago, so I hastily assumed that it was for all iterations :D
Sorry for the confusion Zehir :)
Just ran into this. What's weird is Volar actually knows / infers the type of the item in the collection, so it knows its being used, but also doesn't know its being used.
<template
v-for="item in value"
:key="item.id"
>
In the above, item
autocompletes with id
Any news since last year ? (still getting the error)
Any news since last year ? (still getting the error)
I think https://github.com/vuejs/language-tools/issues/329#issuecomment-886352723 is still the case.
Any news since last year ? (still getting the error)
I think #329 (comment) is still the case.
Is there a relevant issue for Vue regarding this? It's been nearly 3 years, seems like a long time for an issue to exist, albeit one that just causes problems with static analysis tools.
This issue is now resolved, doesn't it work for you? @GRyanParoz
This issue is now resolved, doesn't it work for you? @GRyanParoz
Sorry, I misread the above update. Disregard!
Sorry, I'm a little confused at the discussion above. Is this fixed across the board? I'm still getting a slight warning of an unused variable:
(Note the faded color of index
in the v-for)
vue-tsc
runs fine, so not an issue there. That screenshot is saying the warning is coming from "ts"... so I'm not sure which part of the language tools that's coming from... I guess the language server and ts plugin?
tsconfig.json
package.json
Another thing I just noticed is that hovering over :key="index"
doesn't show a type for index
(or _index
, doesn't matter the name). Actually, no popup shows at all.
EDIT Nevermind, I guess I was several patch versions behind in my vscode extension (thought I had auto-update on). Updated, and now it's working fine!
The below template gives a "'i' is declared but its value is never read." in both volar and vue-tsc.
While the
i
is indeed not used inside the template itself, it is used in the key and can thus not simply be removed.A temporary workaround can be: