@@ -128,16 +128,44 @@ export function toRef<T extends object, K extends keyof T>(
128128// RelativePath extends object -> true
129129type BaseTypes = string | number | boolean | Node | Window
130130
131- // Recursively unwraps nested value bindings.
132- export type UnwrapRef < T > = {
133- cRef : T extends ComputedRef < infer V > ? UnwrapRef < V > : T
134- ref : T extends Ref < infer V > ? UnwrapRef < V > : T
135- array : T
136- object : { [ K in keyof T ] : UnwrapRef < T [ K ] > }
137- } [ T extends ComputedRef < any >
138- ? 'cRef'
139- : T extends Array < any >
140- ? 'array'
141- : T extends Ref | Function | CollectionTypes | BaseTypes
142- ? 'ref' // bail out on types that shouldn't be unwrapped
143- : T extends object ? 'object' : 'ref' ]
131+ export type UnwrapRef < T > = T extends ComputedRef < infer V >
132+ ? UnwrapRefSimple < V >
133+ : T extends Ref < infer V > ? UnwrapRefSimple < V > : UnwrapRefSimple < T >
134+
135+ type UnwrapRefSimple < T > = T extends Function | CollectionTypes | BaseTypes | Ref
136+ ? T
137+ : T extends Array < any > ? T : T extends object ? UnwrappedObject < T > : T
138+
139+ // Extract all known symbols from an object
140+ // when unwrapping Object the symbols are not `in keyof`, this should cover all the
141+ // known symbols
142+ type SymbolExtract < T > = ( T extends { [ Symbol . asyncIterator ] : infer V }
143+ ? { [ Symbol . asyncIterator ] : V }
144+ : { } ) &
145+ ( T extends { [ Symbol . hasInstance ] : infer V }
146+ ? { [ Symbol . hasInstance ] : V }
147+ : { } ) &
148+ ( T extends { [ Symbol . isConcatSpreadable ] : infer V }
149+ ? { [ Symbol . isConcatSpreadable ] : V }
150+ : { } ) &
151+ ( T extends { [ Symbol . iterator ] : infer V } ? { [ Symbol . iterator ] : V } : { } ) &
152+ ( T extends { [ Symbol . match ] : infer V } ? { [ Symbol . match ] : V } : { } ) &
153+ ( T extends { [ Symbol . matchAll ] : infer V } ? { [ Symbol . matchAll ] : V } : { } ) &
154+ ( T extends { [ Symbol . observable ] : infer V }
155+ ? { [ Symbol . observable ] : V }
156+ : { } ) &
157+ ( T extends { [ Symbol . replace ] : infer V } ? { [ Symbol . replace ] : V } : { } ) &
158+ ( T extends { [ Symbol . search ] : infer V } ? { [ Symbol . search ] : V } : { } ) &
159+ ( T extends { [ Symbol . species ] : infer V } ? { [ Symbol . species ] : V } : { } ) &
160+ ( T extends { [ Symbol . split ] : infer V } ? { [ Symbol . split ] : V } : { } ) &
161+ ( T extends { [ Symbol . toPrimitive ] : infer V }
162+ ? { [ Symbol . toPrimitive ] : V }
163+ : { } ) &
164+ ( T extends { [ Symbol . toStringTag ] : infer V }
165+ ? { [ Symbol . toStringTag ] : V }
166+ : { } ) &
167+ ( T extends { [ Symbol . unscopables ] : infer V }
168+ ? { [ Symbol . unscopables ] : V }
169+ : { } )
170+
171+ type UnwrappedObject < T > = { [ P in keyof T ] : UnwrapRef < T [ P ] > } & SymbolExtract < T >
0 commit comments