]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
types: improve type error logging and nest ref types
authorpikax <david-181@hotmail.com>
Sat, 4 Jan 2020 10:10:30 +0000 (10:10 +0000)
committerpikax <david-181@hotmail.com>
Sat, 4 Jan 2020 10:10:53 +0000 (10:10 +0000)
packages/reactivity/src/ref.ts

index e2ff79e185961fc828834364a0da9814f18af8d7..3c3159ce30b907ddf2f7ffc2eaf0e17dcac4d7ca 100644 (file)
@@ -84,18 +84,20 @@ function toProxyRef<T extends object, K extends keyof T>(
 
 type UnwrapArray<T> = { [P in keyof T]: UnwrapRef<T[P]> }
 
-// 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 extends Array<infer V> ? Array<UnwrapRef<V>> & UnwrapArray<T> : T
-  object: { [K in keyof T]: UnwrapRef<T[K]> }
-}[T extends ComputedRef<any>
-  ? 'cRef'
-  : T extends Ref
-    ? 'ref'
-    : T extends Array<any>
-      ? 'array'
-      : T extends Function | CollectionTypes
-        ? 'ref' // bail out on types that shouldn't be unwrapped
-        : T extends object ? 'object' : 'ref']
+type UnwrapProp<T> = T extends ComputedRef<infer V>
+  ? UnwrapRef<V>
+  : T extends Ref<infer V>
+    ? UnwrapRef<V>
+    : T extends Function | CollectionTypes
+      ? T
+      : T extends object
+        ? UnwrapObject<T>
+        : T extends Array<infer V> ? Array<UnwrapRef<V>> & UnwrapArray<T> : T
+
+type UnwrapObject<T> = { [K in keyof T]: UnwrapProp<T[K]> }
+
+export type UnwrapRef<T> = T extends object
+  ? UnwrapObject<T>
+  : T extends Function | CollectionTypes
+    ? T
+    : T extends Array<infer V> ? Array<UnwrapRef<V>> & UnwrapArray<T> : T