Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

ferreraa
Copy link
Contributor

close #8819

When using v-for with an object of type T, the type assigned to the item keys is keyof T.
Since TS 2.9, calling keyof {[key: string]: any} produces a type string | number.

Behind the scenes, vue calls the Object.keys method to produce the keys when using v-for. (see L.81 of renderList.ts)
Object.keys's return type being string[], it sometimes creates a difference between the actual type of the key and the type assigned by vue.

One could argue that keyof is able to provide stricter typing of the keys in some other cases but microsoft deliberately took the decision of typing Object.keys that way and doing differently would only induce more confusion.

Copy link

Size Report

Bundles

File Size Gzip Brotli
runtime-dom.global.prod.js 90.7 kB 34.5 kB 31.1 kB
vue.global.prod.js 148 kB 53.7 kB 48 kB

Usages

Name Size Gzip Brotli
createApp 50.8 kB 19.9 kB 18.1 kB
createSSRApp 54.1 kB 21.2 kB 19.3 kB
defineCustomElement 53.1 kB 20.6 kB 18.8 kB
overall 64.5 kB 24.9 kB 22.6 kB

@haoqunjiang
Copy link
Member

/ecosystem-ci run

@vue-bot
Copy link
Contributor

vue-bot commented May 17, 2024

πŸ“ Ran ecosystem CI: Open

suite result latest scheduled
language-tools βœ… success βœ… success
nuxt βœ… success βœ… success
pinia βœ… success βœ… success
primevue βœ… success βœ… success
quasar βœ… success βœ… success
radix-vue βœ… success βœ… success
router βœ… success βœ… success
test-utils βœ… success βœ… success
vant βœ… success βœ… success
vite-plugin-vue βœ… success βœ… success
vitepress βœ… success βœ… success
vue-i18n βœ… success βœ… success
vue-macros βœ… success βœ… success
vuetify βœ… success βœ… success
vueuse βœ… success βœ… success
vue-simple-compiler βœ… success βœ… success

@haoqunjiang haoqunjiang added the ready to merge The PR is ready to be merged. label May 17, 2024
@haoqunjiang haoqunjiang merged commit 9fead52 into vuejs:main May 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Using v-for on an object with key/value, the key is typed as number
3 participants