From c731610f523fe5893571f7b616c4658daf21959d Mon Sep 17 00:00:00 2001 From: webfansplz <> Date: Thu, 29 Jul 2021 18:51:19 +0800 Subject: [PATCH] types: simplify the UnwrapNestedRefs --- src/reactivity/index.ts | 8 +++++++- src/reactivity/readonly.ts | 4 ++-- src/reactivity/ref.ts | 6 +++++- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/reactivity/index.ts b/src/reactivity/index.ts index c7a9424e..d29d6704 100644 --- a/src/reactivity/index.ts +++ b/src/reactivity/index.ts @@ -22,5 +22,11 @@ export { readonly, isReadonly, shallowReadonly } from './readonly' export { set } from './set' export { del } from './del' -export type { Ref, ToRefs, UnwrapRef, ShallowUnwrapRef } from './ref' +export type { + Ref, + ToRefs, + UnwrapRef, + UnwrapRefSimple, + ShallowUnwrapRef, +} from './ref' export type { DeepReadonly } from './readonly' diff --git a/src/reactivity/readonly.ts b/src/reactivity/readonly.ts index 3c7ebd95..198af428 100644 --- a/src/reactivity/readonly.ts +++ b/src/reactivity/readonly.ts @@ -1,4 +1,4 @@ -import { reactive, Ref, UnwrapRef } from '.' +import { reactive, Ref, UnwrapRefSimple } from '.' import { isArray, isPlainObject, isObject, warn, proxy } from '../utils' import { readonlySet } from '../utils/sets' import { isReactive, observe } from './reactive' @@ -33,7 +33,7 @@ export type DeepReadonly = T extends Builtin : Readonly // only unwrap nested ref -type UnwrapNestedRefs = T extends Ref ? T : UnwrapRef +type UnwrapNestedRefs = T extends Ref ? T : UnwrapRefSimple /** * **In @vue/composition-api, `reactive` only provides type-level readonly check** diff --git a/src/reactivity/ref.ts b/src/reactivity/ref.ts index 455cf3b6..b251f693 100644 --- a/src/reactivity/ref.ts +++ b/src/reactivity/ref.ts @@ -29,7 +29,11 @@ export type UnwrapRef = T extends Ref ? UnwrapRefSimple : UnwrapRefSimple -type UnwrapRefSimple = T extends Function | CollectionTypes | BaseTypes | Ref +export type UnwrapRefSimple = T extends + | Function + | CollectionTypes + | BaseTypes + | Ref ? T : T extends Array ? { [K in keyof T]: UnwrapRefSimple }