Skip to content

Commit

Permalink
fix(apiWatch): handle implicitly any type in watch callback
Browse files Browse the repository at this point in the history
  • Loading branch information
jh-leong committed May 30, 2024
1 parent 6ea95a4 commit 1042d9d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions packages/dts-test/watch.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ watch(readonlyArr, (values, oldValues) => {
expectType<Readonly<[string, string, number]>>(oldValues)
})

// no type error, case from vueuse
declare const aAny: any
watch(aAny, (v, ov) => {})
watch(aAny, (v, ov) => {}, { immediate: true })

// immediate watcher's oldValue will be undefined on first run.
watch(
source,
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime-core/src/apiWatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export function watch<
Immediate extends Readonly<boolean> = false,
>(
sources: readonly [...T] | T,
cb: T extends { [ReactiveMarker]?: true }
cb: [T] extends [{ [ReactiveMarker]?: true }]
? WatchCallback<T, MaybeUndefined<T, Immediate>>
: WatchCallback<MapSources<T, false>, MapSources<T, Immediate>>,
options?: WatchOptions<Immediate>,
Expand Down

0 comments on commit 1042d9d

Please sign in to comment.