// instrument iterators to take ARRAY_ITERATE dependency
function iterator(
self: unknown[],
- method: keyof Array<any>,
+ method: keyof Array<unknown>,
wrapValue: (value: any) => unknown,
) {
// note that taking ARRAY_ITERATE dependency here is not strictly equivalent
// given that JS iterator can only be read once, this doesn't seem like
// a plausible use-case, so this tracking simplification seems ok.
const arr = shallowReadArray(self)
- const iter = (arr[method] as any)()
+ const iter = (arr[method] as any)() as IterableIterator<unknown> & {
+ _next: IterableIterator<unknown>['next']
+ }
if (arr !== self && !isShallow(self)) {
- ;(iter as any)._next = iter.next
+ iter._next = iter.next
iter.next = () => {
- const result = (iter as any)._next()
+ const result = iter._next()
if (result.value) {
result.value = wrapValue(result.value)
}
// but accessing them on Symbol leads to TypeError because Symbol is a strict mode
// function
.filter(key => key !== 'arguments' && key !== 'caller')
- .map(key => (Symbol as any)[key])
+ .map(key => Symbol[key as keyof SymbolConstructor])
.filter(isSymbol),
)
}
set(
- target: object,
+ target: Record<string | symbol, unknown>,
key: string | symbol,
value: unknown,
receiver: object,
): boolean {
- let oldValue = (target as any)[key]
+ let oldValue = target[key]
if (!this._isShallow) {
const isOldValueReadonly = isReadonly(oldValue)
if (!isShallow(value) && !isReadonly(value)) {
return result
}
- deleteProperty(target: object, key: string | symbol): boolean {
+ deleteProperty(
+ target: Record<string | symbol, unknown>,
+ key: string | symbol,
+ ): boolean {
const hadKey = hasOwn(target, key)
- const oldValue = (target as any)[key]
+ const oldValue = target[key]
const result = Reflect.deleteProperty(target, key)
if (result && hadKey) {
trigger(target, TriggerOpTypes.DELETE, key, undefined, oldValue)
return result
}
- has(target: object, key: string | symbol): boolean {
+ has(target: Record<string | symbol, unknown>, key: string | symbol): boolean {
const result = Reflect.has(target, key)
if (!isSymbol(key) || !builtInSymbols.has(key)) {
track(target, TrackOpTypes.HAS, key)
}
return result
}
- ownKeys(target: object): (string | symbol)[] {
+
+ ownKeys(target: Record<string | symbol, unknown>): (string | symbol)[] {
track(
target,
TrackOpTypes.ITERATE,
-import { toRaw, toReactive, toReadonly } from './reactive'
+import { type Target, toRaw, toReactive, toReadonly } from './reactive'
import { ITERATE_KEY, MAP_KEY_ITERATE_KEY, track, trigger } from './dep'
import { ReactiveFlags, TrackOpTypes, TriggerOpTypes } from './constants'
import { capitalize, hasChanged, hasOwn, isMap, toRawType } from '@vue/shared'
type CollectionTypes = IterableCollections | WeakCollections
-type IterableCollections = Map<any, any> | Set<any>
-type WeakCollections = WeakMap<any, any> | WeakSet<any>
-type MapTypes = Map<any, any> | WeakMap<any, any>
-type SetTypes = Set<any> | WeakSet<any>
+type IterableCollections = (Map<any, any> | Set<any>) & Target
+type WeakCollections = (WeakMap<any, any> | WeakSet<any>) & Target
+type MapTypes = (Map<any, any> | WeakMap<any, any>) & Target
+type SetTypes = (Set<any> | WeakSet<any>) & Target
const toShallow = <T extends unknown>(value: T): T => value
) {
// #1772: readonly(reactive(Map)) should return readonly + reactive version
// of the value
- target = (target as any)[ReactiveFlags.RAW]
+ target = target[ReactiveFlags.RAW]
const rawTarget = toRaw(target)
const rawKey = toRaw(key)
if (!isReadonly) {
}
function has(this: CollectionTypes, key: unknown, isReadonly = false): boolean {
- const target = (this as any)[ReactiveFlags.RAW]
+ const target = this[ReactiveFlags.RAW]
const rawTarget = toRaw(target)
const rawKey = toRaw(key)
if (!isReadonly) {
}
function size(target: IterableCollections, isReadonly = false) {
- target = (target as any)[ReactiveFlags.RAW]
+ target = target[ReactiveFlags.RAW]
!isReadonly && track(toRaw(target), TrackOpTypes.ITERATE, ITERATE_KEY)
return Reflect.get(target, 'size', target)
}
callback: Function,
thisArg?: unknown,
) {
- const observed = this as any
+ const observed = this
const target = observed[ReactiveFlags.RAW]
const rawTarget = toRaw(target)
const wrap = isShallow ? toShallow : isReadonly ? toReadonly : toReactive
this: IterableCollections,
...args: unknown[]
): Iterable & Iterator {
- const target = (this as any)[ReactiveFlags.RAW]
+ const target = this[ReactiveFlags.RAW]
const rawTarget = toRaw(target)
const targetIsMap = isMap(rawTarget)
const isPair =