Skip to content

Commit ae81056

Browse files
authored
types: simplify the UnwrapNestedRefs (#777)
Co-authored-by: webfansplz <>
1 parent 21dfe96 commit ae81056

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

src/reactivity/index.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,11 @@ export { readonly, isReadonly, shallowReadonly } from './readonly'
2222
export { set } from './set'
2323
export { del } from './del'
2424

25-
export type { Ref, ToRefs, UnwrapRef, ShallowUnwrapRef } from './ref'
25+
export type {
26+
Ref,
27+
ToRefs,
28+
UnwrapRef,
29+
UnwrapRefSimple,
30+
ShallowUnwrapRef,
31+
} from './ref'
2632
export type { DeepReadonly } from './readonly'

src/reactivity/readonly.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { reactive, Ref, UnwrapRef } from '.'
1+
import { reactive, Ref, UnwrapRefSimple } from '.'
22
import { isArray, isPlainObject, isObject, warn, proxy } from '../utils'
33
import { readonlySet } from '../utils/sets'
44
import { isReactive, observe } from './reactive'
@@ -33,7 +33,7 @@ export type DeepReadonly<T> = T extends Builtin
3333
: Readonly<T>
3434

3535
// only unwrap nested ref
36-
type UnwrapNestedRefs<T> = T extends Ref ? T : UnwrapRef<T>
36+
type UnwrapNestedRefs<T> = T extends Ref ? T : UnwrapRefSimple<T>
3737

3838
/**
3939
* **In @vue/composition-api, `reactive` only provides type-level readonly check**

src/reactivity/ref.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@ export type UnwrapRef<T> = T extends Ref<infer V>
2929
? UnwrapRefSimple<V>
3030
: UnwrapRefSimple<T>
3131

32-
type UnwrapRefSimple<T> = T extends Function | CollectionTypes | BaseTypes | Ref
32+
export type UnwrapRefSimple<T> = T extends
33+
| Function
34+
| CollectionTypes
35+
| BaseTypes
36+
| Ref
3337
? T
3438
: T extends Array<any>
3539
? { [K in keyof T]: UnwrapRefSimple<T[K]> }

0 commit comments

Comments
 (0)