Subscribe on changes!

Typing of v-for :key does not accept symbol

avatar
Aug 3rd 2021

Version

3.2.0-beta.7

Reproduction link

Reproduction link

Steps to reproduce

  1. Use symbols as :key in a v-for.
  2. Compile component incl. template with TypeScript (vue-tsc --noEmit)

What is expected?

Vue allows using a symbol as a v-for :key. This is very useful in some situations, since symbols are an automatically unique primitive. I would expect the typing of v-for :key to include symbol.

What is actually happening?

The code works at runtime, but the type checking step complains that the provided v-for :key is not string | number | undefined.


Symbols have been officially supported as a v-for :key since Vue 2.5. For some reason, the typing (but not the functionality) regressed with Vue 3.0.

We noticed this bug after switching from Vue-cli to Vite, since Vite supports TypeScript in templates out-of-the-box.

avatar
Aug 3rd 2021

I will create a PR with a fix for this.