refactor(types): simplify UnwrapRef + specify iterable method return type (#1444)
This commit is contained in:
parent
c43a6e61a0
commit
f54be6a462
@ -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(
|
function createIterableMethod(
|
||||||
method: string | symbol,
|
method: string | symbol,
|
||||||
isReadonly: boolean,
|
isReadonly: boolean,
|
||||||
shallow: boolean
|
shallow: boolean
|
||||||
) {
|
) {
|
||||||
return function(this: IterableCollections, ...args: unknown[]) {
|
return function(
|
||||||
|
this: IterableCollections,
|
||||||
|
...args: unknown[]
|
||||||
|
): Iterable & Iterator {
|
||||||
const target = toRaw(this)
|
const target = toRaw(this)
|
||||||
const isMap = target instanceof Map
|
const isMap = target instanceof Map
|
||||||
const isPair = method === 'entries' || (method === Symbol.iterator && isMap)
|
const isPair = method === 'entries' || (method === Symbol.iterator && isMap)
|
||||||
|
@ -165,9 +165,10 @@ type UnwrapRefSimple<T> = T extends
|
|||||||
| CollectionTypes
|
| CollectionTypes
|
||||||
| BaseTypes
|
| BaseTypes
|
||||||
| Ref
|
| Ref
|
||||||
|
| Array<any>
|
||||||
| RefUnwrapBailTypes[keyof RefUnwrapBailTypes]
|
| RefUnwrapBailTypes[keyof RefUnwrapBailTypes]
|
||||||
? T
|
? 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
|
// Extract all known symbols from an object
|
||||||
// when unwrapping Object the symbols are not `in keyof`, this should cover all the
|
// when unwrapping Object the symbols are not `in keyof`, this should cover all the
|
||||||
|
Loading…
Reference in New Issue
Block a user