From 0ef0b5e1eb3fca63475edc3958baef99e226b39e Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Thu, 7 Jul 2022 02:35:34 +0800 Subject: [PATCH] chore: fix types --- packages/shared/watchArray/index.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/shared/watchArray/index.ts b/packages/shared/watchArray/index.ts index 0045fbaa4f5..84da09f5fd6 100644 --- a/packages/shared/watchArray/index.ts +++ b/packages/shared/watchArray/index.ts @@ -9,15 +9,20 @@ export declare type WatchArrayCallback = (value: V, oldValue: * @see https://vueuse.org/watchArray */ export function watchArray = false>( - source: WatchSource, + source: WatchSource | T[], cb: WatchArrayCallback, options?: WatchOptions, ) { let oldList: T[] = options?.immediate ? [] - : [...(source instanceof Function ? source() : unref(source))] + : [...(source instanceof Function + ? source() + : Array.isArray(source) + ? source + : unref(source)), + ] - return watch(source, (newList, _, onCleanup) => { + return watch(source as WatchSource, (newList, _, onCleanup) => { const oldListRemains = new Array(oldList.length) const added: T[] = [] for (const obj of newList) {