Skip to content

Commit f54be6a

Browse files
author
Pick
authored
refactor(types): simplify UnwrapRef + specify iterable method return type (#1444)
1 parent c43a6e6 commit f54be6a

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

packages/reactivity/src/collectionHandlers.ts

+17-1
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,28 @@ function createForEach(isReadonly: boolean, shallow: boolean) {
154154
}
155155
}
156156

157+
interface Iterable {
158+
[Symbol.iterator](): Iterator
159+
}
160+
161+
interface Iterator {
162+
next(value?: any): IterationResult
163+
}
164+
165+
interface IterationResult {
166+
value: any
167+
done: boolean
168+
}
169+
157170
function createIterableMethod(
158171
method: string | symbol,
159172
isReadonly: boolean,
160173
shallow: boolean
161174
) {
162-
return function(this: IterableCollections, ...args: unknown[]) {
175+
return function(
176+
this: IterableCollections,
177+
...args: unknown[]
178+
): Iterable & Iterator {
163179
const target = toRaw(this)
164180
const isMap = target instanceof Map
165181
const isPair = method === 'entries' || (method === Symbol.iterator && isMap)

packages/reactivity/src/ref.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,10 @@ type UnwrapRefSimple<T> = T extends
165165
| CollectionTypes
166166
| BaseTypes
167167
| Ref
168+
| Array<any>
168169
| RefUnwrapBailTypes[keyof RefUnwrapBailTypes]
169170
? T
170-
: T extends Array<any> ? T : T extends object ? UnwrappedObject<T> : T
171+
: T extends object ? UnwrappedObject<T> : T
171172

172173
// Extract all known symbols from an object
173174
// when unwrapping Object the symbols are not `in keyof`, this should cover all the

0 commit comments

Comments
 (0)