fix: useParent default value

This commit is contained in:
chenjiahan
2020-09-21 18:54:43 +08:00
parent 63f15094f3
commit ee256e591c
2 changed files with 6 additions and 2 deletions

View File

@@ -4,7 +4,10 @@ type Parent = { children: unknown[] };
type Child<T> = T extends { children: (infer U)[] } ? U : never;
export function useParent<P extends Parent>(key: string, child: Child<P>) {
export function useParent<P extends Parent>(
key: string,
child = {} as Child<P>
) {
const parent = inject<P | null>(key, null);
if (parent) {