1
- import { toRaw , toReactive , toReadonly } from './reactive'
1
+ import { type Target , toRaw , toReactive , toReadonly } from './reactive'
2
2
import { ITERATE_KEY , MAP_KEY_ITERATE_KEY , track , trigger } from './dep'
3
3
import { ReactiveFlags , TrackOpTypes , TriggerOpTypes } from './constants'
4
4
import { capitalize , hasChanged , hasOwn , isMap , toRawType } from '@vue/shared'
5
5
import { warn } from './warning'
6
6
7
7
type CollectionTypes = IterableCollections | WeakCollections
8
8
9
- type IterableCollections = Map < any , any > | Set < any >
10
- type WeakCollections = WeakMap < any , any > | WeakSet < any >
11
- type MapTypes = Map < any , any > | WeakMap < any , any >
12
- type SetTypes = Set < any > | WeakSet < any >
9
+ type IterableCollections = ( Map < any , any > | Set < any > ) & Target
10
+ type WeakCollections = ( WeakMap < any , any > | WeakSet < any > ) & Target
11
+ type MapTypes = ( Map < any , any > | WeakMap < any , any > ) & Target
12
+ type SetTypes = ( Set < any > | WeakSet < any > ) & Target
13
13
14
14
const toShallow = < T extends unknown > ( value : T ) : T => value
15
15
@@ -24,7 +24,7 @@ function get(
24
24
) {
25
25
// #1772: readonly(reactive(Map)) should return readonly + reactive version
26
26
// of the value
27
- target = ( target as any ) [ ReactiveFlags . RAW ]
27
+ target = target [ ReactiveFlags . RAW ]
28
28
const rawTarget = toRaw ( target )
29
29
const rawKey = toRaw ( key )
30
30
if ( ! isReadonly ) {
@@ -47,7 +47,7 @@ function get(
47
47
}
48
48
49
49
function has ( this : CollectionTypes , key : unknown , isReadonly = false ) : boolean {
50
- const target = ( this as any ) [ ReactiveFlags . RAW ]
50
+ const target = this [ ReactiveFlags . RAW ]
51
51
const rawTarget = toRaw ( target )
52
52
const rawKey = toRaw ( key )
53
53
if ( ! isReadonly ) {
@@ -62,7 +62,7 @@ function has(this: CollectionTypes, key: unknown, isReadonly = false): boolean {
62
62
}
63
63
64
64
function size ( target : IterableCollections , isReadonly = false ) {
65
- target = ( target as any ) [ ReactiveFlags . RAW ]
65
+ target = target [ ReactiveFlags . RAW ]
66
66
! isReadonly && track ( toRaw ( target ) , TrackOpTypes . ITERATE , ITERATE_KEY )
67
67
return Reflect . get ( target , 'size' , target )
68
68
}
@@ -144,7 +144,7 @@ function createForEach(isReadonly: boolean, isShallow: boolean) {
144
144
callback : Function ,
145
145
thisArg ?: unknown ,
146
146
) {
147
- const observed = this as any
147
+ const observed = this
148
148
const target = observed [ ReactiveFlags . RAW ]
149
149
const rawTarget = toRaw ( target )
150
150
const wrap = isShallow ? toShallow : isReadonly ? toReadonly : toReactive
@@ -180,7 +180,7 @@ function createIterableMethod(
180
180
this : IterableCollections ,
181
181
...args : unknown [ ]
182
182
) : Iterable & Iterator {
183
- const target = ( this as any ) [ ReactiveFlags . RAW ]
183
+ const target = this [ ReactiveFlags . RAW ]
184
184
const rawTarget = toRaw ( target )
185
185
const targetIsMap = isMap ( rawTarget )
186
186
const isPair =
0 commit comments