types(@vant/use): useChldren support generics (#8136)

This commit is contained in:
neverland 2021-02-12 11:33:31 +08:00 committed by GitHub
parent 26601e9ac3
commit 6ed34d2629
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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);
}
};