]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
refactor(types): simplify UnwrapRef + specify iterable method return type (#1444)
authorPick <pickchen@tencent.com>
Thu, 25 Jun 2020 16:04:14 +0000 (00:04 +0800)
committerGitHub <noreply@github.com>
Thu, 25 Jun 2020 16:04:14 +0000 (12:04 -0400)
packages/reactivity/src/collectionHandlers.ts
packages/reactivity/src/ref.ts

index b9b45c78db8736064a83b1c62939b18db7424375..1e908d960a3610b6b3e7b82b971c6e2d8790ea27 100644 (file)
@@ -154,12 +154,28 @@ function createForEach(isReadonly: boolean, shallow: boolean) {
   }
 }
 
+interface Iterable {
+  [Symbol.iterator](): Iterator
+}
+
+interface Iterator {
+  next(value?: any): IterationResult
+}
+
+interface IterationResult {
+  value: any
+  done: boolean
+}
+
 function createIterableMethod(
   method: string | symbol,
   isReadonly: boolean,
   shallow: boolean
 ) {
-  return function(this: IterableCollections, ...args: unknown[]) {
+  return function(
+    this: IterableCollections,
+    ...args: unknown[]
+  ): Iterable & Iterator {
     const target = toRaw(this)
     const isMap = target instanceof Map
     const isPair = method === 'entries' || (method === Symbol.iterator && isMap)
index 285a9937df73b2fc5855b53efa9f495912263491..fe2b91c94f3e7f2ef01bf9569d55e19321e2a904 100644 (file)
@@ -165,9 +165,10 @@ type UnwrapRefSimple<T> = T extends
   | CollectionTypes
   | BaseTypes
   | Ref
+  | Array<any>
   | RefUnwrapBailTypes[keyof RefUnwrapBailTypes]
   ? T
-  : T extends Array<any> ? T : T extends object ? UnwrappedObject<T> : 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