Skip to content

Commit 1f4fb01

Browse files
chore: optimize TypeScript types
1 parent 7cdd13b commit 1f4fb01

File tree

1 file changed

+17
-21
lines changed

1 file changed

+17
-21
lines changed

packages/reactivity/src/collectionHandlers.ts

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,10 @@ function createReadonlyMethod(type: TriggerOpTypes): Function {
227227
}
228228
}
229229

230+
type Instrumentations = Record<string | symbol, Function | number>
231+
230232
function createInstrumentations() {
231-
const mutableInstrumentations: Record<string, Function | number> = {
233+
const mutableInstrumentations: Instrumentations = {
232234
get(this: MapTypes, key: unknown) {
233235
return get(this, key)
234236
},
@@ -243,7 +245,7 @@ function createInstrumentations() {
243245
forEach: createForEach(false, false)
244246
}
245247

246-
const shallowInstrumentations: Record<string, Function | number> = {
248+
const shallowInstrumentations: Instrumentations = {
247249
get(this: MapTypes, key: unknown) {
248250
return get(this, key, false, true)
249251
},
@@ -258,7 +260,7 @@ function createInstrumentations() {
258260
forEach: createForEach(false, true)
259261
}
260262

261-
const readonlyInstrumentations: Record<string, Function | number> = {
263+
const readonlyInstrumentations: Instrumentations = {
262264
get(this: MapTypes, key: unknown) {
263265
return get(this, key, true)
264266
},
@@ -275,7 +277,7 @@ function createInstrumentations() {
275277
forEach: createForEach(true, false)
276278
}
277279

278-
const shallowReadonlyInstrumentations: Record<string, Function | number> = {
280+
const shallowReadonlyInstrumentations: Instrumentations = {
279281
get(this: MapTypes, key: unknown) {
280282
return get(this, key, true, true)
281283
},
@@ -292,24 +294,18 @@ function createInstrumentations() {
292294
forEach: createForEach(true, true)
293295
}
294296

295-
const iteratorMethods = ['keys', 'values', 'entries', Symbol.iterator]
297+
const iteratorMethods = [
298+
'keys',
299+
'values',
300+
'entries',
301+
Symbol.iterator
302+
] as const
303+
296304
iteratorMethods.forEach(method => {
297-
mutableInstrumentations[method as string] = createIterableMethod(
298-
method,
299-
false,
300-
false
301-
)
302-
readonlyInstrumentations[method as string] = createIterableMethod(
303-
method,
304-
true,
305-
false
306-
)
307-
shallowInstrumentations[method as string] = createIterableMethod(
308-
method,
309-
false,
310-
true
311-
)
312-
shallowReadonlyInstrumentations[method as string] = createIterableMethod(
305+
mutableInstrumentations[method] = createIterableMethod(method, false, false)
306+
readonlyInstrumentations[method] = createIterableMethod(method, true, false)
307+
shallowInstrumentations[method] = createIterableMethod(method, false, true)
308+
shallowReadonlyInstrumentations[method] = createIterableMethod(
313309
method,
314310
true,
315311
true

0 commit comments

Comments
 (0)