Skip to content

Commit 570e13f

Browse files
author
Othmane BENTALEB
committed
fix(reactivity): unwrapped refs typing (fix #9314)
1 parent b8fc18c commit 570e13f

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

packages/reactivity/src/ref.ts

+12-1
Original file line numberDiff line numberDiff line change
@@ -490,14 +490,25 @@ export type UnwrapRef<T> = T extends ShallowRef<infer V>
490490
? UnwrapRefSimple<V>
491491
: UnwrapRefSimple<T>
492492

493+
type UnwrapRefCollection<T extends CollectionTypes> = T extends Set<infer V>
494+
? Set<UnwrapRefSimple<V>>
495+
: T extends Map<infer K, infer V>
496+
? Map<K, UnwrapRefSimple<V>>
497+
: T extends WeakSet<infer V>
498+
? WeakSet<UnwrapRefSimple<V>>
499+
: T extends WeakMap<infer K, infer V>
500+
? WeakMap<K, UnwrapRefSimple<V>>
501+
: T
502+
493503
export type UnwrapRefSimple<T> = T extends
494504
| Function
495-
| CollectionTypes
496505
| BaseTypes
497506
| Ref
498507
| RefUnwrapBailTypes[keyof RefUnwrapBailTypes]
499508
| { [RawSymbol]?: true }
500509
? T
510+
: T extends CollectionTypes
511+
? UnwrapRefCollection<T>
501512
: T extends ReadonlyArray<any>
502513
? { [K in keyof T]: UnwrapRefSimple<T[K]> }
503514
: T extends object & { [ShallowReactiveMarker]?: never }

0 commit comments

Comments
 (0)