mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
types: improve use relation typing
This commit is contained in:
parent
50fc123b3e
commit
c2513c5934
@ -1,7 +1,7 @@
|
|||||||
import { ref, Ref, provide, inject, computed, onUnmounted } from 'vue';
|
import { ref, Ref, provide, inject, computed, onUnmounted } from 'vue';
|
||||||
|
|
||||||
export type Parent = null | {
|
export type Parent<T = unknown> = null | {
|
||||||
children: Ref<unknown[]>;
|
children: Ref<Ref<T>[]>;
|
||||||
};
|
};
|
||||||
|
|
||||||
export function useChildren(key: string) {
|
export function useChildren(key: string) {
|
||||||
@ -10,8 +10,8 @@ export function useChildren(key: string) {
|
|||||||
return children;
|
return children;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useParent(key: string, child: unknown) {
|
export function useParent<T = unknown>(key: string, child: Ref<T>) {
|
||||||
const parent = inject<Parent>(key, null);
|
const parent = inject<Parent<T>>(key, null);
|
||||||
|
|
||||||
if (parent) {
|
if (parent) {
|
||||||
const children = parent.children.value;
|
const children = parent.children.value;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user