|
|
@@ -128,16 +128,44 @@ export function toRef<T extends object, K extends keyof T>(
|
|
|
// RelativePath extends object -> true
|
|
|
type BaseTypes = string | number | boolean | Node | Window
|
|
|
|
|
|
-// Recursively unwraps nested value bindings.
|
|
|
-export type UnwrapRef<T> = {
|
|
|
- cRef: T extends ComputedRef<infer V> ? UnwrapRef<V> : T
|
|
|
- ref: T extends Ref<infer V> ? UnwrapRef<V> : T
|
|
|
- array: T
|
|
|
- object: { [K in keyof T]: UnwrapRef<T[K]> }
|
|
|
-}[T extends ComputedRef<any>
|
|
|
- ? 'cRef'
|
|
|
- : T extends Array<any>
|
|
|
- ? 'array'
|
|
|
- : T extends Ref | Function | CollectionTypes | BaseTypes
|
|
|
- ? 'ref' // bail out on types that shouldn't be unwrapped
|
|
|
- : T extends object ? 'object' : 'ref']
|
|
|
+export type UnwrapRef<T> = T extends ComputedRef<infer V>
|
|
|
+ ? UnwrapRefSimple<V>
|
|
|
+ : T extends Ref<infer V> ? UnwrapRefSimple<V> : UnwrapRefSimple<T>
|
|
|
+
|
|
|
+type UnwrapRefSimple<T> = T extends Function | CollectionTypes | BaseTypes | Ref
|
|
|
+ ? T
|
|
|
+ : T extends Array<any> ? T : T extends object ? UnwrappedObject<T> : T
|
|
|
+
|
|
|
+// Extract all known symbols from an object
|
|
|
+// when unwrapping Object the symbols are not `in keyof`, this should cover all the
|
|
|
+// known symbols
|
|
|
+type SymbolExtract<T> = (T extends { [Symbol.asyncIterator]: infer V }
|
|
|
+ ? { [Symbol.asyncIterator]: V }
|
|
|
+ : {}) &
|
|
|
+ (T extends { [Symbol.hasInstance]: infer V }
|
|
|
+ ? { [Symbol.hasInstance]: V }
|
|
|
+ : {}) &
|
|
|
+ (T extends { [Symbol.isConcatSpreadable]: infer V }
|
|
|
+ ? { [Symbol.isConcatSpreadable]: V }
|
|
|
+ : {}) &
|
|
|
+ (T extends { [Symbol.iterator]: infer V } ? { [Symbol.iterator]: V } : {}) &
|
|
|
+ (T extends { [Symbol.match]: infer V } ? { [Symbol.match]: V } : {}) &
|
|
|
+ (T extends { [Symbol.matchAll]: infer V } ? { [Symbol.matchAll]: V } : {}) &
|
|
|
+ (T extends { [Symbol.observable]: infer V }
|
|
|
+ ? { [Symbol.observable]: V }
|
|
|
+ : {}) &
|
|
|
+ (T extends { [Symbol.replace]: infer V } ? { [Symbol.replace]: V } : {}) &
|
|
|
+ (T extends { [Symbol.search]: infer V } ? { [Symbol.search]: V } : {}) &
|
|
|
+ (T extends { [Symbol.species]: infer V } ? { [Symbol.species]: V } : {}) &
|
|
|
+ (T extends { [Symbol.split]: infer V } ? { [Symbol.split]: V } : {}) &
|
|
|
+ (T extends { [Symbol.toPrimitive]: infer V }
|
|
|
+ ? { [Symbol.toPrimitive]: V }
|
|
|
+ : {}) &
|
|
|
+ (T extends { [Symbol.toStringTag]: infer V }
|
|
|
+ ? { [Symbol.toStringTag]: V }
|
|
|
+ : {}) &
|
|
|
+ (T extends { [Symbol.unscopables]: infer V }
|
|
|
+ ? { [Symbol.unscopables]: V }
|
|
|
+ : {})
|
|
|
+
|
|
|
+type UnwrappedObject<T> = { [P in keyof T]: UnwrapRef<T[P]> } & SymbolExtract<T>
|