core icon indicating copy to clipboard operation
core copied to clipboard

WatchCallback returns `void`, not `any`

Open rotu opened this issue 1 year ago • 4 comments

This matches the documentation and better expresses that the return value is (mostly) ignored.

rotu avatar Dec 11 '24 19:12 rotu

Size Report

Bundles

File Size Gzip Brotli
runtime-dom.global.prod.js 100 kB 37.9 kB 34.2 kB
vue.global.prod.js 158 kB 57.8 kB 51.4 kB

Usages

Name Size Gzip Brotli
createApp (CAPI only) 46.6 kB 18.3 kB 16.7 kB
createApp 54.6 kB 21.3 kB 19.4 kB
createSSRApp 58.7 kB 23 kB 20.9 kB
defineCustomElement 59.4 kB 22.8 kB 20.8 kB
overall 68.4 kB 26.4 kB 24 kB

github-actions[bot] avatar Dec 11 '24 19:12 github-actions[bot]

Open in Stackblitz

@vue/compiler-core

npm i https://pkg.pr.new/@vue/compiler-core@12531
@vue/compiler-sfc

npm i https://pkg.pr.new/@vue/compiler-sfc@12531
@vue/compiler-ssr

npm i https://pkg.pr.new/@vue/compiler-ssr@12531
@vue/compiler-dom

npm i https://pkg.pr.new/@vue/compiler-dom@12531
@vue/runtime-core

npm i https://pkg.pr.new/@vue/runtime-core@12531
@vue/runtime-dom

npm i https://pkg.pr.new/@vue/runtime-dom@12531
@vue/reactivity

npm i https://pkg.pr.new/@vue/reactivity@12531
@vue/server-renderer

npm i https://pkg.pr.new/@vue/server-renderer@12531
@vue/shared

npm i https://pkg.pr.new/@vue/shared@12531
vue

npm i https://pkg.pr.new/vue@12531
@vue/compat

npm i https://pkg.pr.new/@vue/compat@12531

commit: 09e84ef

pkg-pr-new[bot] avatar Dec 11 '24 19:12 pkg-pr-new[bot]

Maybe both the docs and the return type of WatchCallback should be changed to undefined | Promise<undefined>?

void provides very little type-checking since a function returning void may return any value.

Relevant discussion: https://github.com/microsoft/TypeScript/issues/42709

rotu avatar Dec 11 '24 20:12 rotu

I'm not clear what the correct type should be, but a couple of observations:

  1. This seems a similar idea to #5914. In that case the decision was to use any.
  2. The return types for WatchCallback and WatchEffect are currently different (any and void respectively). I would've expected them to be the same.

skirtles-code avatar May 18 '25 19:05 skirtles-code