Skip to content

Commit

Permalink
chore: ensure consistent usage of indexed object access style in Type…
Browse files Browse the repository at this point in the history
…Script code
  • Loading branch information
Alfred-Skyblue committed Sep 10, 2023
1 parent 80c7df7 commit cb7aea3
Show file tree
Hide file tree
Showing 15 changed files with 20 additions and 29 deletions.
2 changes: 2 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ module.exports = {
],
// Enforce the use of top-level import type qualifier when an import only has specifiers with inline type qualifiers
'@typescript-eslint/no-import-type-side-effects': 'error',
// Ensure consistent usage of indexed object access style in TypeScript code.
'@typescript-eslint/consistent-indexed-object-style': 'error',
},
overrides: [
// tests, no restrictions (runs in Node / jest with jsdom)
Expand Down
7 changes: 4 additions & 3 deletions packages/compiler-core/__tests__/parse.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2157,13 +2157,14 @@ foo
})

describe('Errors', () => {
const patterns: {
[key: string]: Array<{
const patterns: Record<
string,
Array<{
code: string
errors: Array<{ type: ErrorCodes; loc: Position }>
options?: Partial<ParserOptions>
}>
} = {
> = {
ABRUPT_CLOSING_OF_EMPTY_COMMENT: [
{
code: '<template><!--></template>',
Expand Down
2 changes: 1 addition & 1 deletion packages/compiler-core/__tests__/testUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export function createElementWithCodegen(
type Flags = PatchFlags | ShapeFlags
export function genFlagText(
flag: Flags | Flags[],
names: { [k: number]: string } = PatchFlagNames,
names: Record<number, string> = PatchFlagNames,
) {
if (isArray(flag)) {
let f = 0
Expand Down
2 changes: 1 addition & 1 deletion packages/compiler-core/src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type InferCompilerError<T> = T extends ErrorCodes
export function createCompilerError<T extends number>(
code: T,
loc?: SourceLocation,
messages?: { [code: number]: string },
messages?: Record<number, string>,
additionalMessage?: string,
): InferCompilerError<T> {
const msg =
Expand Down
4 changes: 1 addition & 3 deletions packages/compiler-core/src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,7 @@ export const enum BindingTypes {
LITERAL_CONST = 'literal-const',
}

export type BindingMetadata = {
[key: string]: BindingTypes | undefined
} & {
export type BindingMetadata = Record<string, BindingTypes | undefined> & {
__isScriptSetup?: boolean
__propsAliases?: Record<string, string>
}
Expand Down
2 changes: 1 addition & 1 deletion packages/compiler-core/src/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export interface TransformContext
imports: ImportItem[]
temps: number
cached: number
identifiers: { [name: string]: number | undefined }
identifiers: Record<string, number | undefined>
scopes: {
vFor: number
vSlot: number
Expand Down
2 changes: 1 addition & 1 deletion packages/compiler-dom/src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ if (__TEST__) {
}
}

export const DOMErrorMessages: { [code: number]: string } = {
export const DOMErrorMessages: Record<number, string> = {
[DOMErrorCodes.X_V_HTML_NO_EXPRESSION]: `v-html is missing expression.`,
[DOMErrorCodes.X_V_HTML_WITH_CHILDREN]: `v-html will override element children.`,
[DOMErrorCodes.X_V_TEXT_NO_EXPRESSION]: `v-text is missing expression.`,
Expand Down
4 changes: 1 addition & 3 deletions packages/compiler-sfc/src/template/transformAssetUrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ import {
} from './templateUtils'
import { isArray } from '@vue/shared'

export interface AssetURLTagConfig {
[name: string]: string[]
}
export type AssetURLTagConfig = Record<string, string[]>

export interface AssetURLOptions {
/**
Expand Down
2 changes: 1 addition & 1 deletion packages/compiler-ssr/src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ if (__TEST__) {
}
}

export const SSRErrorMessages: { [code: number]: string } = {
export const SSRErrorMessages: Record<number, string> = {
[SSRErrorCodes.X_SSR_UNSAFE_ATTR_NAME]: `Unsafe attribute name for SSR.`,
[SSRErrorCodes.X_SSR_NO_TELEPORT_TARGET]: `Missing the 'to' prop on teleport element.`,
[SSRErrorCodes.X_SSR_INVALID_AST_NODE]: `Invalid AST node during SSR transform.`,
Expand Down
4 changes: 1 addition & 3 deletions packages/runtime-core/src/compat/instanceEventEmitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ import type { ComponentInternalInstance } from '../component'
import { callWithAsyncErrorHandling, ErrorCodes } from '../errorHandling'
import { assertCompatEnabled, DeprecationTypes } from './compatConfig'

interface EventRegistry {
[event: string]: Function[] | undefined
}
type EventRegistry = Record<string, Function[] | undefined>

const eventRegistryMap = /*#__PURE__*/ new WeakMap<
ComponentInternalInstance,
Expand Down
4 changes: 1 addition & 3 deletions packages/runtime-core/src/componentOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -411,9 +411,7 @@ export type ComputedOptions = Record<
ComputedGetter<any> | WritableComputedOptions<any>
>

export interface MethodOptions {
[key: string]: Function
}
export type MethodOptions = Record<string, Function>

export type ExtractComputedReturns<T extends any> = {
[key in keyof T]: T[key] extends { get: (...args: any[]) => infer TReturn }
Expand Down
4 changes: 1 addition & 3 deletions packages/runtime-core/src/componentSlots.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ export type Slot<T extends any = any> = (
...args: IfAny<T, any[], [T] | (T extends undefined ? [] : never)>
) => VNode[]

export type InternalSlots = {
[name: string]: Slot | undefined
}
export type InternalSlots = Record<string, Slot | undefined>

export type Slots = Readonly<InternalSlots>

Expand Down
6 changes: 2 additions & 4 deletions packages/runtime-core/src/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export interface RendererOptions<
type: string,
isSVG?: boolean,
isCustomizedBuiltIn?: string,
vnodeProps?: (VNodeProps & { [key: string]: any }) | null,
vnodeProps?: (VNodeProps & Record<string, any>) | null,
): HostElement
createText(text: string): HostNode
createComment(text: string): HostNode
Expand All @@ -134,9 +134,7 @@ export interface RendererOptions<
// logic - they are never directly operated on and always passed to the node op
// functions provided via options, so the internal constraint is really just
// a generic object.
export interface RendererNode {
[key: string]: any
}
export type RendererNode = Record<string, any>

export interface RendererElement extends RendererNode {}

Expand Down
2 changes: 1 addition & 1 deletion packages/runtime-core/src/vnode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export type VNodeNormalizedChildren =
export interface VNode<
HostNode = RendererNode,
HostElement = RendererElement,
ExtraProps = { [key: string]: any },
ExtraProps = Record<string, any>,
> {
/**
* @internal
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/src/general.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { makeMap } from './makeMap'

export const EMPTY_OBJ: { readonly [key: string]: any } = __DEV__
export const EMPTY_OBJ: Readonly<Record<string, any>> = __DEV__
? Object.freeze({})
: {}
export const EMPTY_ARR = __DEV__ ? Object.freeze([]) : []
Expand Down

0 comments on commit cb7aea3

Please sign in to comment.