mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-05-04 23:06:35 +08:00
types: improve useParent typing
This commit is contained in:
parent
7d0340a35b
commit
5359120ed3
@ -1,11 +1,11 @@
|
|||||||
import { inject, computed, onUnmounted } from 'vue';
|
import { inject, computed, onUnmounted } from 'vue';
|
||||||
|
|
||||||
export type Parent<T = unknown> = null | {
|
type Parent = { children: unknown[] };
|
||||||
children: T[];
|
|
||||||
};
|
|
||||||
|
|
||||||
export function useParent<T = unknown>(key: string, child: T = {} as T) {
|
type Child<T> = T extends { children: (infer U)[] } ? U : never;
|
||||||
const parent = inject<Parent<T>>(key, null);
|
|
||||||
|
export function useParent<P extends Parent>(key: string, child: Child<P>) {
|
||||||
|
const parent = inject<P | null>(key, null);
|
||||||
|
|
||||||
if (parent) {
|
if (parent) {
|
||||||
const { children } = parent;
|
const { children } = parent;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user