Skip to content

Commit

Permalink
types: simplify the UnwrapNestedRefs (#777)
Browse files Browse the repository at this point in the history
Co-authored-by: webfansplz <>
  • Loading branch information
webfansplz authored Jul 30, 2021
1 parent 21dfe96 commit ae81056
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
8 changes: 7 additions & 1 deletion src/reactivity/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
4 changes: 2 additions & 2 deletions src/reactivity/readonly.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -33,7 +33,7 @@ export type DeepReadonly<T> = T extends Builtin
: Readonly<T>

// only unwrap nested ref
type UnwrapNestedRefs<T> = T extends Ref ? T : UnwrapRef<T>
type UnwrapNestedRefs<T> = T extends Ref ? T : UnwrapRefSimple<T>

/**
* **In @vue/composition-api, `reactive` only provides type-level readonly check**
Expand Down
6 changes: 5 additions & 1 deletion src/reactivity/ref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ export type UnwrapRef<T> = T extends Ref<infer V>
? UnwrapRefSimple<V>
: UnwrapRefSimple<T>

type UnwrapRefSimple<T> = T extends Function | CollectionTypes | BaseTypes | Ref
export type UnwrapRefSimple<T> = T extends
| Function
| CollectionTypes
| BaseTypes
| Ref
? T
: T extends Array<any>
? { [K in keyof T]: UnwrapRefSimple<T[K]> }
Expand Down

0 comments on commit ae81056

Please sign in to comment.