vuejs / core

🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
https://vuejs.org/
MIT License
47.8k stars 8.35k forks source link

fix(types): defineEmits w/ interface declaration #12343

Closed edison1105 closed 1 week ago

edison1105 commented 2 weeks ago

close #8457

github-actions[bot] commented 2 weeks ago

Size Report

Bundles

File Size Gzip Brotli
runtime-dom.global.prod.js 100 kB 38 kB 34.2 kB
vue.global.prod.js 159 kB 57.9 kB 51.4 kB

Usages

Name Size Gzip Brotli
createApp (CAPI only) 46.9 kB 18.3 kB 16.7 kB
createApp 55 kB 21.3 kB 19.4 kB
createSSRApp 59 kB 23 kB 21 kB
defineCustomElement 59.8 kB 22.8 kB 20.8 kB
overall 68.7 kB 26.3 kB 24 kB
pkg-pr-new[bot] commented 2 weeks ago

Open in Stackblitz

@vue/compiler-core

``` pnpm add https://pkg.pr.new/@vue/compiler-core@12343 ```

@vue/compiler-sfc

``` pnpm add https://pkg.pr.new/@vue/compiler-sfc@12343 ```

@vue/compiler-ssr

``` pnpm add https://pkg.pr.new/@vue/compiler-ssr@12343 ```

@vue/compiler-dom

``` pnpm add https://pkg.pr.new/@vue/compiler-dom@12343 ```

@vue/reactivity

``` pnpm add https://pkg.pr.new/@vue/reactivity@12343 ```

@vue/runtime-core

``` pnpm add https://pkg.pr.new/@vue/runtime-core@12343 ```

@vue/runtime-dom

``` pnpm add https://pkg.pr.new/@vue/runtime-dom@12343 ```

@vue/server-renderer

``` pnpm add https://pkg.pr.new/@vue/server-renderer@12343 ```

@vue/shared

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

vue

``` pnpm add https://pkg.pr.new/vue@12343 ```

@vue/compat

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

commit: c4e9b3f

yyx990803 commented 1 week ago

This widens the type constraint for the interface, but I think it's worth it.

If the user writes something like

interface Emits {
  bar: 1 // !!!!
}

Now it will be allowed, but the emit function will expect ...args to be of type 1, which will never be satisfied, so that serves as a safeguard against misuse.