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

fix(compiler-core): change v-for key type to match Object.keys #10963

Merged
merged 1 commit into from
May 20, 2024

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

@sodatea
Copy link
Member

sodatea commented May 17, 2024

/ecosystem-ci run

@vue-bot
Copy link

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

@sodatea sodatea added the ready to merge The PR is ready to be merged. label May 17, 2024
@sodatea sodatea merged commit 9fead52 into vuejs:main May 20, 2024
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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