Skip to content

[@vue/reactivity] watch() doesn't accept TS generics #13807

@Maxim-Mazurok

Description

@Maxim-Mazurok

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:

export function watch(

What is expected?

Please let's add similar generics as @vue/runtime-core:

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?

Image

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions