]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
types: bring back my changes
authorpikax <carlos@hypermob.co.uk>
Wed, 8 Apr 2020 20:33:06 +0000 (21:33 +0100)
committerpikax <carlos@hypermob.co.uk>
Wed, 8 Apr 2020 20:34:00 +0000 (21:34 +0100)
packages/reactivity/src/ref.ts
packages/runtime-core/__tests__/apiTemplateRef.spec.ts

index 3b334538c11ac6c57b0063352c7f42cf472ae549..485f5646271154f30de6132d2634942bcf7a2c8a 100644 (file)
@@ -103,16 +103,27 @@ function toProxyRef<T extends object, K extends keyof T>(
 // RelativePath extends object -> true
 type BaseTypes = string | number | boolean
 
-// 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']
+// Super simple tuple checker
+type Tupple<T extends Array<any>> = T[0] extends T[1]
+  ? T[1] extends T[2] ? never : true
+  : true
+
+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<infer V>
+    ? Tupple<T> extends never ? Array<V> : UnwrapTupple<T>
+    : T extends object ? UnwrappedObject<T> : T
+
+export type UnwrapTupple<T> = { [P in keyof T]: T[P] } & {
+  length: number
+  [Symbol.iterator]: any
+  [Symbol.unscopables]: any
+}
+
+// interface UnwrappedArray<T> extends Array<T> {}
+
+type UnwrappedObject<T> = { [P in keyof T]: UnwrapRef<T[P]> }
index 1ba8526aa9bcfff088fbe5b84aa2821b17da9d3e..acf4f5b37f06bb4260714c5cb2c74b1445c75458 100644 (file)
@@ -4,7 +4,6 @@ import {
   h,
   render,
   nextTick,
-  Ref,
   defineComponent,
   reactive
 } from '@vue/runtime-test'