Skip to content

Commit

Permalink
fix(reactivity): unwrapped refs typing (fix #9314)
Browse files Browse the repository at this point in the history
  • Loading branch information
Othmane BENTALEB committed Oct 5, 2023
1 parent b8fc18c commit 570e13f
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion packages/reactivity/src/ref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -490,14 +490,25 @@ export type UnwrapRef<T> = T extends ShallowRef<infer V>
? UnwrapRefSimple<V>
: UnwrapRefSimple<T>

type UnwrapRefCollection<T extends CollectionTypes> = T extends Set<infer V>
? Set<UnwrapRefSimple<V>>
: T extends Map<infer K, infer V>
? Map<K, UnwrapRefSimple<V>>
: T extends WeakSet<infer V>
? WeakSet<UnwrapRefSimple<V>>
: T extends WeakMap<infer K, infer V>
? WeakMap<K, UnwrapRefSimple<V>>
: T

export type UnwrapRefSimple<T> = T extends
| Function
| CollectionTypes
| BaseTypes
| Ref
| RefUnwrapBailTypes[keyof RefUnwrapBailTypes]
| { [RawSymbol]?: true }
? T
: T extends CollectionTypes
? UnwrapRefCollection<T>
: T extends ReadonlyArray<any>
? { [K in keyof T]: UnwrapRefSimple<T[K]> }
: T extends object & { [ShallowReactiveMarker]?: never }
Expand Down

0 comments on commit 570e13f

Please sign in to comment.