From 6ed34d26292a24913d3a047d7099e56b59ff2196 Mon Sep 17 00:00:00 2001 From: neverland Date: Fri, 12 Feb 2021 11:33:31 +0800 Subject: [PATCH] types(@vant/use): useChldren support generics (#8136) --- packages/vant-use/src/useRelation/useChildren.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/vant-use/src/useRelation/useChildren.ts b/packages/vant-use/src/useRelation/useChildren.ts index dce0b72b7..6a7610af5 100644 --- a/packages/vant-use/src/useRelation/useChildren.ts +++ b/packages/vant-use/src/useRelation/useChildren.ts @@ -56,8 +56,10 @@ export function sortChildren( }); } -export function useChildren(key: string | symbol) { - const publicChildren: ComponentPublicInstance[] = reactive([]); +export function useChildren< + Child extends ComponentPublicInstance = ComponentPublicInstance +>(key: string | symbol) { + const publicChildren: Child[] = reactive([]); const internalChildren: ComponentInternalInstance[] = reactive([]); const parent = getCurrentInstance()!; @@ -65,7 +67,7 @@ export function useChildren(key: string | symbol) { const link = (child: ComponentInternalInstance) => { if (child.proxy) { internalChildren.push(child); - publicChildren.push(child.proxy); + publicChildren.push(child.proxy as Child); sortChildren(parent, publicChildren, internalChildren); } };