diff --git a/.eslintrc.js b/.eslintrc.js index 6b295a6c27a..8ab899ae5f1 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -31,6 +31,10 @@ module.exports = defineConfig({ eqeqeq: ['error', 'always', { null: 'ignore' }], 'prefer-template': 'error', + '@typescript-eslint/array-type': [ + 'error', + { default: 'array-simple', readonly: 'generic' }, + ], '@typescript-eslint/ban-ts-comment': 'error', '@typescript-eslint/consistent-type-imports': 'error', '@typescript-eslint/explicit-module-boundary-types': 'error', diff --git a/scripts/apidoc/utils.ts b/scripts/apidoc/utils.ts index 7939adb1106..f480c0b10cc 100644 --- a/scripts/apidoc/utils.ts +++ b/scripts/apidoc/utils.ts @@ -3,7 +3,7 @@ import { resolve } from 'node:path'; // Types export type Page = { text: string; link: string }; -export type PageIndex = Array; +export type PageIndex = Page[]; // Paths @@ -14,7 +14,7 @@ export const pathOutputDir = resolve(pathDocsDir, 'api'); // Functions export function mapByName( - input: Array, + input: T[], valueExtractor: (item: T) => V ): Record { return input.reduce( diff --git a/src/definitions/science.ts b/src/definitions/science.ts index 29e4f59e189..b63767f6f7e 100644 --- a/src/definitions/science.ts +++ b/src/definitions/science.ts @@ -8,10 +8,10 @@ export type ScienceDefinitions = LocaleEntry<{ /** * Some science units. */ - unit: readonly Unit[]; + unit: ReadonlyArray; /** * Some periodic table element information. */ - chemicalElement: readonly ChemicalElement[]; + chemicalElement: ReadonlyArray; }>; diff --git a/src/modules/helpers/index.ts b/src/modules/helpers/index.ts index a4ecdf71c06..c22a3612052 100644 --- a/src/modules/helpers/index.ts +++ b/src/modules/helpers/index.ts @@ -284,7 +284,7 @@ export class HelpersModule { * @since 2.0.1 */ shuffle( - list: readonly T[], + list: ReadonlyArray, options?: { /** * Whether to shuffle the array in place or return a new array. @@ -351,7 +351,7 @@ export class HelpersModule { * * @since 6.0.0 */ - uniqueArray(source: readonly T[] | (() => T), length: number): T[] { + uniqueArray(source: ReadonlyArray | (() => T), length: number): T[] { if (Array.isArray(source)) { const set = new Set(source); const array = Array.from(set); diff --git a/src/modules/internet/index.ts b/src/modules/internet/index.ts index f07ab973a14..3287e4048bc 100644 --- a/src/modules/internet/index.ts +++ b/src/modules/internet/index.ts @@ -320,7 +320,7 @@ export class InternetModule { const { types = Object.keys( this.faker.definitions.internet.http_status_code - ) as Array, + ) as HTTPStatusCodeType[], } = options; const httpStatusCodeType = this.faker.helpers.arrayElement(types); return this.faker.helpers.arrayElement( @@ -627,9 +627,7 @@ export class InternetModule { } = {} ): string { const { - types = Object.keys( - this.faker.definitions.internet.emoji - ) as Array, + types = Object.keys(this.faker.definitions.internet.emoji) as EmojiType[], } = options; const emojiType = this.faker.helpers.arrayElement(types); return this.faker.helpers.arrayElement( diff --git a/src/modules/random/index.ts b/src/modules/random/index.ts index d558e24b5d7..4936fe80e88 100644 --- a/src/modules/random/index.ts +++ b/src/modules/random/index.ts @@ -221,7 +221,7 @@ export class RandomModule { * * @default [] */ - bannedChars?: readonly LiteralUnion[] | string; + bannedChars?: ReadonlyArray> | string; } = {} ): string { deprecated({ @@ -274,7 +274,7 @@ export class RandomModule { * * @default [] */ - bannedChars?: readonly LiteralUnion[] | string; + bannedChars?: ReadonlyArray> | string; } = {} ): string { deprecated({ @@ -325,7 +325,7 @@ export class RandomModule { * * @default [] */ - bannedDigits?: readonly LiteralUnion[] | string; + bannedDigits?: ReadonlyArray> | string; } = {} ): string { deprecated({ diff --git a/src/modules/string/index.ts b/src/modules/string/index.ts index 8f62788adad..6240184cfad 100644 --- a/src/modules/string/index.ts +++ b/src/modules/string/index.ts @@ -4,9 +4,13 @@ import type { LiteralUnion } from '../../utils/types'; export type Casing = 'upper' | 'lower' | 'mixed'; -const UPPER_CHARS: readonly string[] = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.split(''); -const LOWER_CHARS: readonly string[] = 'abcdefghijklmnopqrstuvwxyz'.split(''); -const DIGIT_CHARS: readonly string[] = '0123456789'.split(''); +const UPPER_CHARS: ReadonlyArray = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.split( + '' +); +const LOWER_CHARS: ReadonlyArray = 'abcdefghijklmnopqrstuvwxyz'.split( + '' +); +const DIGIT_CHARS: ReadonlyArray = '0123456789'.split(''); export type LowerAlphaChar = | 'a' @@ -200,7 +204,7 @@ export class StringModule { * * @default [] */ - exclude?: readonly LiteralUnion[] | string; + exclude?: ReadonlyArray> | string; } = {} ): string { if (typeof options === 'number') { @@ -290,7 +294,7 @@ export class StringModule { * * @default [] */ - exclude?: readonly LiteralUnion[] | string; + exclude?: ReadonlyArray> | string; } = {} ): string { if (typeof options === 'number') { @@ -567,7 +571,7 @@ export class StringModule { * * @default [] */ - exclude?: readonly LiteralUnion[] | string; + exclude?: ReadonlyArray> | string; } = {} ): string { if (typeof options === 'number') { diff --git a/test/faker.spec.ts b/test/faker.spec.ts index 75d515f7519..12121b9d073 100644 --- a/test/faker.spec.ts +++ b/test/faker.spec.ts @@ -51,7 +51,7 @@ describe('faker', () => { }); it('should not log anything on startup', () => { - const spies: Array = Object.keys(console) + const spies: SpyInstance[] = Object.keys(console) .filter((key) => typeof console[key] === 'function') .map((methodName) => vi.spyOn(console, methodName as keyof typeof console) diff --git a/test/scripts/apidoc/examplesAndDeprecations.spec.ts b/test/scripts/apidoc/examplesAndDeprecations.spec.ts index ac73244c1ac..8d6124e0321 100644 --- a/test/scripts/apidoc/examplesAndDeprecations.spec.ts +++ b/test/scripts/apidoc/examplesAndDeprecations.spec.ts @@ -41,7 +41,7 @@ beforeAll(initMarkdownRenderer); describe('examples and deprecations', () => { const modules = loadProjectModules(); - const consoleSpies: Array = Object.keys(console) + const consoleSpies: SpyInstance[] = Object.keys(console) .filter((key) => typeof console[key] === 'function') .map((methodName) => vi.spyOn(console, methodName as keyof typeof console)); diff --git a/test/scripts/apidoc/signature.example.ts b/test/scripts/apidoc/signature.example.ts index e99256262f4..26c35923c6e 100644 --- a/test/scripts/apidoc/signature.example.ts +++ b/test/scripts/apidoc/signature.example.ts @@ -142,10 +142,10 @@ export class SignatureTest { literalUnionParamMethod( value: LiteralUnion<'a' | 'b'>, namedValue: LiteralUnion, - array: readonly LiteralUnion<'a' | 'b'>[], - namedArray: readonly LiteralUnion[], - mixed: LiteralUnion<'a' | 'b'> | readonly LiteralUnion<'a' | 'b'>[], - namedMixed: readonly LiteralUnion[] | LiteralUnion + array: ReadonlyArray>, + namedArray: ReadonlyArray>, + mixed: LiteralUnion<'a' | 'b'> | ReadonlyArray>, + namedMixed: ReadonlyArray> | LiteralUnion ): string { return ( value +