From 315f6abbd2466de22907201dd45be796db9e8a95 Mon Sep 17 00:00:00 2001 From: MinatoHikari <35342316+MinatoHikari@users.noreply.github.com> Date: Sun, 16 Jan 2022 16:55:48 +0800 Subject: [PATCH] fix(types): update inject and unref type (#888) --- src/apis/inject.ts | 7 ++++++- src/reactivity/ref.ts | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/apis/inject.ts b/src/apis/inject.ts index a8feaf2d..e94c7a2b 100644 --- a/src/apis/inject.ts +++ b/src/apis/inject.ts @@ -47,7 +47,12 @@ export function inject(key: InjectionKey | string): T | undefined export function inject( key: InjectionKey | string, defaultValue: T, - treatDefaultAsFactory?: boolean + treatDefaultAsFactory?: false +): T +export function inject( + key: InjectionKey | string, + defaultValue: T | (() => T), + treatDefaultAsFactory?: true ): T export function inject( key: InjectionKey | string, diff --git a/src/reactivity/ref.ts b/src/reactivity/ref.ts index a7a73a44..044a63df 100644 --- a/src/reactivity/ref.ts +++ b/src/reactivity/ref.ts @@ -113,7 +113,7 @@ export function isRef(value: any): value is Ref { return value instanceof RefImpl } -export function unref(ref: T): T extends Ref ? V : T { +export function unref(ref: T | Ref): T { return isRef(ref) ? (ref.value as any) : ref }