Skip to content

Commit cb7aea3

Browse files
chore: ensure consistent usage of indexed object access style in TypeScript code
1 parent 80c7df7 commit cb7aea3

File tree

15 files changed

+20
-29
lines changed

15 files changed

+20
-29
lines changed

.eslintrc.cjs

+2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ module.exports = {
4343
],
4444
// Enforce the use of top-level import type qualifier when an import only has specifiers with inline type qualifiers
4545
'@typescript-eslint/no-import-type-side-effects': 'error',
46+
// Ensure consistent usage of indexed object access style in TypeScript code.
47+
'@typescript-eslint/consistent-indexed-object-style': 'error',
4648
},
4749
overrides: [
4850
// tests, no restrictions (runs in Node / jest with jsdom)

packages/compiler-core/__tests__/parse.spec.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -2157,13 +2157,14 @@ foo
21572157
})
21582158

21592159
describe('Errors', () => {
2160-
const patterns: {
2161-
[key: string]: Array<{
2160+
const patterns: Record<
2161+
string,
2162+
Array<{
21622163
code: string
21632164
errors: Array<{ type: ErrorCodes; loc: Position }>
21642165
options?: Partial<ParserOptions>
21652166
}>
2166-
} = {
2167+
> = {
21672168
ABRUPT_CLOSING_OF_EMPTY_COMMENT: [
21682169
{
21692170
code: '<template><!--></template>',

packages/compiler-core/__tests__/testUtils.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export function createElementWithCodegen(
7878
type Flags = PatchFlags | ShapeFlags
7979
export function genFlagText(
8080
flag: Flags | Flags[],
81-
names: { [k: number]: string } = PatchFlagNames,
81+
names: Record<number, string> = PatchFlagNames,
8282
) {
8383
if (isArray(flag)) {
8484
let f = 0

packages/compiler-core/src/errors.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ type InferCompilerError<T> = T extends ErrorCodes
2424
export function createCompilerError<T extends number>(
2525
code: T,
2626
loc?: SourceLocation,
27-
messages?: { [code: number]: string },
27+
messages?: Record<number, string>,
2828
additionalMessage?: string,
2929
): InferCompilerError<T> {
3030
const msg =

packages/compiler-core/src/options.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,7 @@ export const enum BindingTypes {
124124
LITERAL_CONST = 'literal-const',
125125
}
126126

127-
export type BindingMetadata = {
128-
[key: string]: BindingTypes | undefined
129-
} & {
127+
export type BindingMetadata = Record<string, BindingTypes | undefined> & {
130128
__isScriptSetup?: boolean
131129
__propsAliases?: Record<string, string>
132130
}

packages/compiler-core/src/transform.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ export interface TransformContext
9696
imports: ImportItem[]
9797
temps: number
9898
cached: number
99-
identifiers: { [name: string]: number | undefined }
99+
identifiers: Record<string, number | undefined>
100100
scopes: {
101101
vFor: number
102102
vSlot: number

packages/compiler-dom/src/errors.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ if (__TEST__) {
4848
}
4949
}
5050

51-
export const DOMErrorMessages: { [code: number]: string } = {
51+
export const DOMErrorMessages: Record<number, string> = {
5252
[DOMErrorCodes.X_V_HTML_NO_EXPRESSION]: `v-html is missing expression.`,
5353
[DOMErrorCodes.X_V_HTML_WITH_CHILDREN]: `v-html will override element children.`,
5454
[DOMErrorCodes.X_V_TEXT_NO_EXPRESSION]: `v-text is missing expression.`,

packages/compiler-sfc/src/template/transformAssetUrl.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ import {
1717
} from './templateUtils'
1818
import { isArray } from '@vue/shared'
1919

20-
export interface AssetURLTagConfig {
21-
[name: string]: string[]
22-
}
20+
export type AssetURLTagConfig = Record<string, string[]>
2321

2422
export interface AssetURLOptions {
2523
/**

packages/compiler-ssr/src/errors.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ if (__TEST__) {
3535
}
3636
}
3737

38-
export const SSRErrorMessages: { [code: number]: string } = {
38+
export const SSRErrorMessages: Record<number, string> = {
3939
[SSRErrorCodes.X_SSR_UNSAFE_ATTR_NAME]: `Unsafe attribute name for SSR.`,
4040
[SSRErrorCodes.X_SSR_NO_TELEPORT_TARGET]: `Missing the 'to' prop on teleport element.`,
4141
[SSRErrorCodes.X_SSR_INVALID_AST_NODE]: `Invalid AST node during SSR transform.`,

packages/runtime-core/src/compat/instanceEventEmitter.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ import type { ComponentInternalInstance } from '../component'
33
import { callWithAsyncErrorHandling, ErrorCodes } from '../errorHandling'
44
import { assertCompatEnabled, DeprecationTypes } from './compatConfig'
55

6-
interface EventRegistry {
7-
[event: string]: Function[] | undefined
8-
}
6+
type EventRegistry = Record<string, Function[] | undefined>
97

108
const eventRegistryMap = /*#__PURE__*/ new WeakMap<
119
ComponentInternalInstance,

packages/runtime-core/src/componentOptions.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -411,9 +411,7 @@ export type ComputedOptions = Record<
411411
ComputedGetter<any> | WritableComputedOptions<any>
412412
>
413413

414-
export interface MethodOptions {
415-
[key: string]: Function
416-
}
414+
export type MethodOptions = Record<string, Function>
417415

418416
export type ExtractComputedReturns<T extends any> = {
419417
[key in keyof T]: T[key] extends { get: (...args: any[]) => infer TReturn }

packages/runtime-core/src/componentSlots.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@ export type Slot<T extends any = any> = (
3030
...args: IfAny<T, any[], [T] | (T extends undefined ? [] : never)>
3131
) => VNode[]
3232

33-
export type InternalSlots = {
34-
[name: string]: Slot | undefined
35-
}
33+
export type InternalSlots = Record<string, Slot | undefined>
3634

3735
export type Slots = Readonly<InternalSlots>
3836

packages/runtime-core/src/renderer.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ export interface RendererOptions<
109109
type: string,
110110
isSVG?: boolean,
111111
isCustomizedBuiltIn?: string,
112-
vnodeProps?: (VNodeProps & { [key: string]: any }) | null,
112+
vnodeProps?: (VNodeProps & Record<string, any>) | null,
113113
): HostElement
114114
createText(text: string): HostNode
115115
createComment(text: string): HostNode
@@ -134,9 +134,7 @@ export interface RendererOptions<
134134
// logic - they are never directly operated on and always passed to the node op
135135
// functions provided via options, so the internal constraint is really just
136136
// a generic object.
137-
export interface RendererNode {
138-
[key: string]: any
139-
}
137+
export type RendererNode = Record<string, any>
140138

141139
export interface RendererElement extends RendererNode {}
142140

packages/runtime-core/src/vnode.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ export type VNodeNormalizedChildren =
144144
export interface VNode<
145145
HostNode = RendererNode,
146146
HostElement = RendererElement,
147-
ExtraProps = { [key: string]: any },
147+
ExtraProps = Record<string, any>,
148148
> {
149149
/**
150150
* @internal

packages/shared/src/general.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { makeMap } from './makeMap'
22

3-
export const EMPTY_OBJ: { readonly [key: string]: any } = __DEV__
3+
export const EMPTY_OBJ: Readonly<Record<string, any>> = __DEV__
44
? Object.freeze({})
55
: {}
66
export const EMPTY_ARR = __DEV__ ? Object.freeze([]) : []

0 commit comments

Comments
 (0)