core icon indicating copy to clipboard operation
core copied to clipboard

types(runtime-core): fix type constraints for `default` in `PropOptions`

Open jh-leong opened this issue 1 year ago • 10 comments

close #12145

Correct the default field type to prevent assigning arbitrary objects.

refix #1891. If type specifies a Function, the default field type should match the specified function type.


NOTE: Due to TypeScript's literal-inference, when type is a literal type, the default cannot be strictly enforced.

Consider the following example:

// `foo.default` is inferred as `string` instead of the literal type `'foo'`
const foo = {
  type: String as PropType<'foo' | 'bar'>,
  default: 'foo',
}

// Strictly enforcing `default` to be `'foo' | 'bar'` would break existing cases:
defineComponent({
  props: { foo }, // should allow
})

jh-leong avatar Oct 21 '24 06:10 jh-leong

Size Report

Bundles

File Size Gzip Brotli
runtime-dom.global.prod.js 99.7 kB 37.8 kB 34.1 kB
vue.global.prod.js 158 kB 57.7 kB 51.3 kB

Usages

Name Size Gzip Brotli
createApp (CAPI only) 47 kB 18.3 kB 16.7 kB
createApp 55.1 kB 21.3 kB 19.4 kB
createSSRApp 59.1 kB 23 kB 20.9 kB
defineCustomElement 59.9 kB 22.9 kB 20.8 kB
overall 68.9 kB 26.4 kB 24 kB

github-actions[bot] avatar Oct 21 '24 06:10 github-actions[bot]

Open in Stackblitz

@vue/compiler-core

pnpm add https://pkg.pr.new/@vue/compiler-core@12227
@vue/compiler-dom

pnpm add https://pkg.pr.new/@vue/compiler-dom@12227
@vue/compiler-ssr

pnpm add https://pkg.pr.new/@vue/compiler-ssr@12227
@vue/compiler-sfc

pnpm add https://pkg.pr.new/@vue/compiler-sfc@12227
@vue/reactivity

pnpm add https://pkg.pr.new/@vue/reactivity@12227
@vue/runtime-core

pnpm add https://pkg.pr.new/@vue/runtime-core@12227
@vue/runtime-dom

pnpm add https://pkg.pr.new/@vue/runtime-dom@12227
@vue/server-renderer

pnpm add https://pkg.pr.new/@vue/server-renderer@12227
@vue/shared

pnpm add https://pkg.pr.new/@vue/shared@12227
vue

pnpm add https://pkg.pr.new/vue@12227
@vue/compat

pnpm add https://pkg.pr.new/@vue/compat@12227

commit: 89e80b2

pkg-pr-new[bot] avatar Oct 21 '24 06:10 pkg-pr-new[bot]

/ecosystem-ci run

jh-leong avatar Oct 21 '24 06:10 jh-leong

📝 Ran ecosystem CI: Open

suite result latest scheduled
language-tools :x: failure :white_check_mark: success
nuxt :white_check_mark: success :white_check_mark: success
pinia :white_check_mark: success :white_check_mark: success
primevue :white_check_mark: success :white_check_mark: success
quasar :white_check_mark: success :white_check_mark: success
radix-vue :white_check_mark: success :white_check_mark: success
router :white_check_mark: success :white_check_mark: success
test-utils :white_check_mark: success :white_check_mark: success
vant :white_check_mark: success :white_check_mark: success
vite-plugin-vue :white_check_mark: success :white_check_mark: success
vitepress :white_check_mark: success :white_check_mark: success
vue-i18n :white_check_mark: success :white_check_mark: success
vue-macros :white_check_mark: success :white_check_mark: success
vuetify :white_check_mark: success :white_check_mark: success
vueuse :white_check_mark: success :white_check_mark: success
vue-simple-compiler :white_check_mark: success :white_check_mark: success

vue-bot avatar Oct 21 '24 06:10 vue-bot

/ecosystem-ci run language-tools

jh-leong avatar Oct 21 '24 07:10 jh-leong

📝 Ran ecosystem CI: Open

suite result latest scheduled
language-tools :x: failure :white_check_mark: success

vue-bot avatar Oct 21 '24 07:10 vue-bot

/ecosystem-ci run language-tools

jh-leong avatar Oct 21 '24 08:10 jh-leong

📝 Ran ecosystem CI: Open

suite result latest scheduled
language-tools :white_check_mark: success :white_check_mark: success

vue-bot avatar Oct 21 '24 08:10 vue-bot

/ecosystem-ci run

jh-leong avatar Oct 22 '24 02:10 jh-leong

📝 Ran ecosystem CI: Open

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

vue-bot avatar Oct 22 '24 02:10 vue-bot