-
-
Notifications
You must be signed in to change notification settings - Fork 8.9k
Open
Labels
Description
Vue version
3.5.20
Link to minimal reproduction
N/A
Steps to reproduce
watch()
from @vue/reactivity
doesn't accept generic <T>
type arguments, so the new/old value types are any
:
core/packages/reactivity/src/watch.ts
Line 120 in 24fccb4
export function watch( |
What is expected?
Please let's add similar generics as @vue/runtime-core
:
core/packages/runtime-core/src/apiWatch.ts
Lines 87 to 126 in 24fccb4
export function watch<T, Immediate extends Readonly<boolean> = false>( | |
source: WatchSource<T>, | |
cb: WatchCallback<T, MaybeUndefined<T, Immediate>>, | |
options?: WatchOptions<Immediate>, | |
): WatchHandle | |
// overload: reactive array or tuple of multiple sources + cb | |
export function watch< | |
T extends Readonly<MultiWatchSources>, | |
Immediate extends Readonly<boolean> = false, | |
>( | |
sources: readonly [...T] | T, | |
cb: [T] extends [ReactiveMarker] | |
? WatchCallback<T, MaybeUndefined<T, Immediate>> | |
: WatchCallback<MapSources<T, false>, MapSources<T, Immediate>>, | |
options?: WatchOptions<Immediate>, | |
): WatchHandle | |
// overload: array of multiple sources + cb | |
export function watch< | |
T extends MultiWatchSources, | |
Immediate extends Readonly<boolean> = false, | |
>( | |
sources: [...T], | |
cb: WatchCallback<MapSources<T, false>, MapSources<T, Immediate>>, | |
options?: WatchOptions<Immediate>, | |
): WatchHandle | |
// overload: watching reactive object w/ cb | |
export function watch< | |
T extends object, | |
Immediate extends Readonly<boolean> = false, | |
>( | |
source: T, | |
cb: WatchCallback<T, MaybeUndefined<T, Immediate>>, | |
options?: WatchOptions<Immediate>, | |
): WatchHandle | |
// implementation | |
export function watch<T = any, Immediate extends Readonly<boolean> = false>( |
Thank you!
What is actually happening?

System Info
System:
OS: Linux 6.6 Ubuntu 24.04.3 LTS 24.04.3 LTS (Noble Numbat)
CPU: (20) x64 12th Gen Intel(R) Core(TM) i9-12900H
Memory: 24.99 GB / 31.18 GB
Container: Yes
Shell: 5.2.21 - /bin/bash
Binaries:
Node: 24.6.0 - ~/.nvm/versions/node/v24.6.0/bin/node
npm: 11.5.1 - ~/.nvm/versions/node/v24.6.0/bin/npm
pnpm: 9.4.0 - ~/.local/share/pnpm/pnpm
Browsers:
Chrome: 139.0.7258.138
Any additional comments?
Using in NodeJS environment, not for FE
jinndi