From e7230f6f10af9633cf0eca18910cbafaaba9ecba Mon Sep 17 00:00:00 2001 From: Shinigami Date: Wed, 15 Feb 2023 19:29:44 +0100 Subject: chore: activate noImplicitAny (#1839) --- src/modules/airline/index.ts | 4 +++- src/modules/animal/index.ts | 4 +++- src/modules/color/index.ts | 4 +++- src/modules/commerce/index.ts | 4 +++- src/modules/company/index.ts | 4 +++- src/modules/database/index.ts | 4 +++- src/modules/datatype/index.ts | 4 +++- src/modules/date/index.ts | 4 +++- src/modules/finance/index.ts | 4 +++- src/modules/git/index.ts | 4 +++- src/modules/hacker/index.ts | 4 +++- src/modules/helpers/index.ts | 18 ++++++++++++++---- src/modules/helpers/unique.ts | 8 +++++++- src/modules/image/index.ts | 8 ++++++-- src/modules/image/providers/placeholder.ts | 4 +++- src/modules/internet/index.ts | 4 +++- src/modules/location/index.ts | 4 +++- src/modules/lorem/index.ts | 4 +++- src/modules/music/index.ts | 4 +++- src/modules/number/index.ts | 4 +++- src/modules/person/index.ts | 4 +++- src/modules/phone/index.ts | 4 +++- src/modules/random/index.ts | 4 +++- src/modules/science/index.ts | 4 +++- src/modules/string/index.ts | 4 +++- src/modules/system/index.ts | 4 +++- src/modules/vehicle/index.ts | 4 +++- src/modules/word/index.ts | 4 +++- src/utils/types.ts | 11 ++++++++--- 29 files changed, 110 insertions(+), 35 deletions(-) (limited to 'src') diff --git a/src/modules/airline/index.ts b/src/modules/airline/index.ts index 3a5a400c..aeeb4873 100644 --- a/src/modules/airline/index.ts +++ b/src/modules/airline/index.ts @@ -66,7 +66,9 @@ const aircraftTypeSeats: Record = { export class AirlineModule { constructor(private readonly faker: Faker) { // Bind `this` so namespaced is working correctly - for (const name of Object.getOwnPropertyNames(AirlineModule.prototype)) { + for (const name of Object.getOwnPropertyNames( + AirlineModule.prototype + ) as Array) { if (name === 'constructor' || typeof this[name] !== 'function') { continue; } diff --git a/src/modules/animal/index.ts b/src/modules/animal/index.ts index 3cd9d71e..90efc7ab 100644 --- a/src/modules/animal/index.ts +++ b/src/modules/animal/index.ts @@ -6,7 +6,9 @@ import type { Faker } from '../..'; export class AnimalModule { constructor(private readonly faker: Faker) { // Bind `this` so namespaced is working correctly - for (const name of Object.getOwnPropertyNames(AnimalModule.prototype)) { + for (const name of Object.getOwnPropertyNames( + AnimalModule.prototype + ) as Array) { if (name === 'constructor' || typeof this[name] !== 'function') { continue; } diff --git a/src/modules/color/index.ts b/src/modules/color/index.ts index 981dae60..67fa9b9a 100644 --- a/src/modules/color/index.ts +++ b/src/modules/color/index.ts @@ -160,7 +160,9 @@ function toColorFormat( export class ColorModule { constructor(private readonly faker: Faker) { // Bind `this` so namespaced is working correctly - for (const name of Object.getOwnPropertyNames(ColorModule.prototype)) { + for (const name of Object.getOwnPropertyNames( + ColorModule.prototype + ) as Array) { if (name === 'constructor' || typeof this[name] !== 'function') { continue; } diff --git a/src/modules/commerce/index.ts b/src/modules/commerce/index.ts index 66f6d02c..54d2bce1 100644 --- a/src/modules/commerce/index.ts +++ b/src/modules/commerce/index.ts @@ -7,7 +7,9 @@ import { deprecated } from '../../internal/deprecated'; export class CommerceModule { constructor(private readonly faker: Faker) { // Bind `this` so namespaced is working correctly - for (const name of Object.getOwnPropertyNames(CommerceModule.prototype)) { + for (const name of Object.getOwnPropertyNames( + CommerceModule.prototype + ) as Array) { if (name === 'constructor' || typeof this[name] !== 'function') { continue; } diff --git a/src/modules/company/index.ts b/src/modules/company/index.ts index 79f2fa8f..467256c7 100644 --- a/src/modules/company/index.ts +++ b/src/modules/company/index.ts @@ -7,7 +7,9 @@ import { deprecated } from '../../internal/deprecated'; export class CompanyModule { constructor(private readonly faker: Faker) { // Bind `this` so namespaced is working correctly - for (const name of Object.getOwnPropertyNames(CompanyModule.prototype)) { + for (const name of Object.getOwnPropertyNames( + CompanyModule.prototype + ) as Array) { if (name === 'constructor' || typeof this[name] !== 'function') { continue; } diff --git a/src/modules/database/index.ts b/src/modules/database/index.ts index 922f4b0e..88a7609a 100644 --- a/src/modules/database/index.ts +++ b/src/modules/database/index.ts @@ -6,7 +6,9 @@ import type { Faker } from '../..'; export class DatabaseModule { constructor(private readonly faker: Faker) { // Bind `this` so namespaced is working correctly - for (const name of Object.getOwnPropertyNames(DatabaseModule.prototype)) { + for (const name of Object.getOwnPropertyNames( + DatabaseModule.prototype + ) as Array) { if (name === 'constructor' || typeof this[name] !== 'function') { continue; } diff --git a/src/modules/datatype/index.ts b/src/modules/datatype/index.ts index 25235bb5..7410e149 100644 --- a/src/modules/datatype/index.ts +++ b/src/modules/datatype/index.ts @@ -7,7 +7,9 @@ import { deprecated } from '../../internal/deprecated'; export class DatatypeModule { constructor(private readonly faker: Faker) { // Bind `this` so namespaced is working correctly - for (const name of Object.getOwnPropertyNames(DatatypeModule.prototype)) { + for (const name of Object.getOwnPropertyNames( + DatatypeModule.prototype + ) as Array) { if (name === 'constructor' || typeof this[name] !== 'function') { continue; } diff --git a/src/modules/date/index.ts b/src/modules/date/index.ts index c99a7d19..d7a0f12a 100644 --- a/src/modules/date/index.ts +++ b/src/modules/date/index.ts @@ -28,7 +28,9 @@ function toDate( export class DateModule { constructor(private readonly faker: Faker) { // Bind `this` so namespaced is working correctly - for (const name of Object.getOwnPropertyNames(DateModule.prototype)) { + for (const name of Object.getOwnPropertyNames( + DateModule.prototype + ) as Array) { if (name === 'constructor' || typeof this[name] !== 'function') { continue; } diff --git a/src/modules/finance/index.ts b/src/modules/finance/index.ts index d137ee1b..8db5bfce 100644 --- a/src/modules/finance/index.ts +++ b/src/modules/finance/index.ts @@ -8,7 +8,9 @@ import iban from './iban'; export class FinanceModule { constructor(private readonly faker: Faker) { // Bind `this` so namespaced is working correctly - for (const name of Object.getOwnPropertyNames(FinanceModule.prototype)) { + for (const name of Object.getOwnPropertyNames( + FinanceModule.prototype + ) as Array) { if (name === 'constructor' || typeof this[name] !== 'function') { continue; } diff --git a/src/modules/git/index.ts b/src/modules/git/index.ts index 394f9610..5a963840 100644 --- a/src/modules/git/index.ts +++ b/src/modules/git/index.ts @@ -24,7 +24,9 @@ const GIT_TIMEZONE_FORMAT = new Intl.NumberFormat('en', { export class GitModule { constructor(private readonly faker: Faker) { // Bind `this` so namespaced is working correctly - for (const name of Object.getOwnPropertyNames(GitModule.prototype)) { + for (const name of Object.getOwnPropertyNames(GitModule.prototype) as Array< + keyof GitModule | 'constructor' + >) { if (name === 'constructor' || typeof this[name] !== 'function') { continue; } diff --git a/src/modules/hacker/index.ts b/src/modules/hacker/index.ts index aadf839a..00b9a686 100644 --- a/src/modules/hacker/index.ts +++ b/src/modules/hacker/index.ts @@ -6,7 +6,9 @@ import type { Faker } from '../..'; export class HackerModule { constructor(private readonly faker: Faker) { // Bind `this` so namespaced is working correctly - for (const name of Object.getOwnPropertyNames(HackerModule.prototype)) { + for (const name of Object.getOwnPropertyNames( + HackerModule.prototype + ) as Array) { if (name === 'constructor' || typeof this[name] !== 'function') { continue; } diff --git a/src/modules/helpers/index.ts b/src/modules/helpers/index.ts index c22a3612..55732f4a 100644 --- a/src/modules/helpers/index.ts +++ b/src/modules/helpers/index.ts @@ -10,7 +10,9 @@ import * as uniqueExec from './unique'; export class HelpersModule { constructor(private readonly faker: Faker) { // Bind `this` so namespaced is working correctly - for (const name of Object.getOwnPropertyNames(HelpersModule.prototype)) { + for (const name of Object.getOwnPropertyNames( + HelpersModule.prototype + ) as Array) { if (name === 'constructor' || typeof this[name] !== 'function') { continue; } @@ -804,8 +806,10 @@ export class HelpersModule { // Search for the requested method or definition for (const part of parts) { - currentModuleOrMethod = currentModuleOrMethod?.[part]; - currentDefinitions = currentDefinitions?.[part]; + currentModuleOrMethod = + currentModuleOrMethod?.[part as keyof typeof currentModuleOrMethod]; + currentDefinitions = + currentDefinitions?.[part as keyof typeof currentDefinitions]; } // Make method executable @@ -903,7 +907,13 @@ export class HelpersModule { * * @since 7.5.0 */ - unique RecordKey>( + unique< + Method extends ( + // TODO christopher 2023-02-14: This `any` type can be fixed by anyone if they want to. + // eslint-disable-next-line @typescript-eslint/no-explicit-any + ...parameters: any[] + ) => RecordKey + >( method: Method, args?: Parameters, options: { diff --git a/src/modules/helpers/unique.ts b/src/modules/helpers/unique.ts index fd240c2f..ebd1b88e 100644 --- a/src/modules/helpers/unique.ts +++ b/src/modules/helpers/unique.ts @@ -81,7 +81,13 @@ Try adjusting maxTime or maxRetries parameters for faker.helpers.unique().` * @param options.compare The function used to determine whether a value was already returned. Defaults to check the existence of the key. * @param options.store The store of unique entries. Defaults to `GLOBAL_UNIQUE_STORE`. */ -export function exec RecordKey>( +export function exec< + Method extends ( + // TODO christopher 2023-02-14: This `any` type can be fixed by anyone if they want to. + // eslint-disable-next-line @typescript-eslint/no-explicit-any + ...parameters: any[] + ) => RecordKey +>( method: Method, args: Parameters, options: { diff --git a/src/modules/image/index.ts b/src/modules/image/index.ts index 794a9514..ac42dc25 100644 --- a/src/modules/image/index.ts +++ b/src/modules/image/index.ts @@ -26,12 +26,16 @@ export class ImageModule { constructor(private readonly faker: Faker) { // Bind `this` so namespaced is working correctly - for (const name of Object.getOwnPropertyNames(ImageModule.prototype)) { + for (const name of Object.getOwnPropertyNames( + ImageModule.prototype + ) as Array) { if (name === 'constructor' || typeof this[name] !== 'function') { continue; } - this[name] = this[name].bind(this); + this[name] = + // @ts-expect-error: remove this expect-error when we remove the deprecated sub-modules + this[name].bind(this); } this.unsplash = new Unsplash(this.faker); diff --git a/src/modules/image/providers/placeholder.ts b/src/modules/image/providers/placeholder.ts index 9691a9ff..0101e681 100644 --- a/src/modules/image/providers/placeholder.ts +++ b/src/modules/image/providers/placeholder.ts @@ -9,7 +9,9 @@ import { deprecated } from '../../../internal/deprecated'; export class Placeholder { constructor(private readonly faker: Faker) { // Bind `this` so namespaced is working correctly - for (const name of Object.getOwnPropertyNames(Placeholder.prototype)) { + for (const name of Object.getOwnPropertyNames( + Placeholder.prototype + ) as Array) { if (name === 'constructor' || typeof this[name] !== 'function') { continue; } diff --git a/src/modules/internet/index.ts b/src/modules/internet/index.ts index 3287e404..2623f8b3 100644 --- a/src/modules/internet/index.ts +++ b/src/modules/internet/index.ts @@ -29,7 +29,9 @@ export type HTTPProtocolType = 'http' | 'https'; export class InternetModule { constructor(private readonly faker: Faker) { // Bind `this` so namespaced is working correctly - for (const name of Object.getOwnPropertyNames(InternetModule.prototype)) { + for (const name of Object.getOwnPropertyNames( + InternetModule.prototype + ) as Array) { if (name === 'constructor' || typeof this[name] !== 'function') { continue; } diff --git a/src/modules/location/index.ts b/src/modules/location/index.ts index 5fe542cb..4ce28bcf 100644 --- a/src/modules/location/index.ts +++ b/src/modules/location/index.ts @@ -7,7 +7,9 @@ import { deprecated } from '../../internal/deprecated'; export class LocationModule { constructor(private readonly faker: Faker) { // Bind `this` so namespaced is working correctly - for (const name of Object.getOwnPropertyNames(LocationModule.prototype)) { + for (const name of Object.getOwnPropertyNames( + LocationModule.prototype + ) as Array) { if (name === 'constructor' || typeof this[name] !== 'function') { continue; } diff --git a/src/modules/lorem/index.ts b/src/modules/lorem/index.ts index 9c9b514f..4e124929 100644 --- a/src/modules/lorem/index.ts +++ b/src/modules/lorem/index.ts @@ -7,7 +7,9 @@ import { filterWordListByLength } from '../word/filterWordListByLength'; export class LoremModule { constructor(private readonly faker: Faker) { // Bind `this` so namespaced is working correctly - for (const name of Object.getOwnPropertyNames(LoremModule.prototype)) { + for (const name of Object.getOwnPropertyNames( + LoremModule.prototype + ) as Array) { if (name === 'constructor' || typeof this[name] !== 'function') { continue; } diff --git a/src/modules/music/index.ts b/src/modules/music/index.ts index e25ade68..15d282d4 100644 --- a/src/modules/music/index.ts +++ b/src/modules/music/index.ts @@ -6,7 +6,9 @@ import type { Faker } from '../..'; export class MusicModule { constructor(private readonly faker: Faker) { // Bind `this` so namespaced is working correctly - for (const name of Object.getOwnPropertyNames(MusicModule.prototype)) { + for (const name of Object.getOwnPropertyNames( + MusicModule.prototype + ) as Array) { if (name === 'constructor' || typeof this[name] !== 'function') { continue; } diff --git a/src/modules/number/index.ts b/src/modules/number/index.ts index 96e5067d..3cd35f40 100644 --- a/src/modules/number/index.ts +++ b/src/modules/number/index.ts @@ -8,7 +8,9 @@ import type { Mersenne } from '../../internal/mersenne/mersenne'; export class NumberModule { constructor(private readonly faker: Faker) { // Bind `this` so namespaced is working correctly - for (const name of Object.getOwnPropertyNames(NumberModule.prototype)) { + for (const name of Object.getOwnPropertyNames( + NumberModule.prototype + ) as Array) { if (name === 'constructor' || typeof this[name] !== 'function') { continue; } diff --git a/src/modules/person/index.ts b/src/modules/person/index.ts index da30fee7..ccbb8e14 100644 --- a/src/modules/person/index.ts +++ b/src/modules/person/index.ts @@ -61,7 +61,9 @@ function selectDefinition( export class PersonModule { constructor(private readonly faker: Faker) { // Bind `this` so namespaced is working correctly - for (const name of Object.getOwnPropertyNames(PersonModule.prototype)) { + for (const name of Object.getOwnPropertyNames( + PersonModule.prototype + ) as Array) { if (name === 'constructor' || typeof this[name] !== 'function') { continue; } diff --git a/src/modules/phone/index.ts b/src/modules/phone/index.ts index 437464bf..d604c44a 100644 --- a/src/modules/phone/index.ts +++ b/src/modules/phone/index.ts @@ -6,7 +6,9 @@ import type { Faker } from '../..'; export class PhoneModule { constructor(private readonly faker: Faker) { // Bind `this` so namespaced is working correctly - for (const name of Object.getOwnPropertyNames(PhoneModule.prototype)) { + for (const name of Object.getOwnPropertyNames( + PhoneModule.prototype + ) as Array) { if (name === 'constructor' || typeof this[name] !== 'function') { continue; } diff --git a/src/modules/random/index.ts b/src/modules/random/index.ts index 4936fe80..c12df82d 100644 --- a/src/modules/random/index.ts +++ b/src/modules/random/index.ts @@ -14,7 +14,9 @@ import type { export class RandomModule { constructor(private readonly faker: Faker) { // Bind `this` so namespaced is working correctly - for (const name of Object.getOwnPropertyNames(RandomModule.prototype)) { + for (const name of Object.getOwnPropertyNames( + RandomModule.prototype + ) as Array) { if (name === 'constructor' || typeof this[name] !== 'function') { continue; } diff --git a/src/modules/science/index.ts b/src/modules/science/index.ts index 7dba5d3d..754bcbdf 100644 --- a/src/modules/science/index.ts +++ b/src/modules/science/index.ts @@ -35,7 +35,9 @@ export interface Unit { export class ScienceModule { constructor(private readonly faker: Faker) { // Bind `this` so namespaced is working correctly - for (const name of Object.getOwnPropertyNames(ScienceModule.prototype)) { + for (const name of Object.getOwnPropertyNames( + ScienceModule.prototype + ) as Array) { if (name === 'constructor' || typeof this[name] !== 'function') { continue; } diff --git a/src/modules/string/index.ts b/src/modules/string/index.ts index 188c91eb..f6180df3 100644 --- a/src/modules/string/index.ts +++ b/src/modules/string/index.ts @@ -91,7 +91,9 @@ const SAMPLE_MAX_LENGTH = 2 ** 20; export class StringModule { constructor(private readonly faker: Faker) { // Bind `this` so namespaced is working correctly - for (const name of Object.getOwnPropertyNames(StringModule.prototype)) { + for (const name of Object.getOwnPropertyNames( + StringModule.prototype + ) as Array) { if (name === 'constructor' || typeof this[name] !== 'function') { continue; } diff --git a/src/modules/system/index.ts b/src/modules/system/index.ts index 2f3ce371..35ca2c8d 100644 --- a/src/modules/system/index.ts +++ b/src/modules/system/index.ts @@ -38,7 +38,9 @@ const CRON_DAY_OF_WEEK = [ export class SystemModule { constructor(private readonly faker: Faker) { // Bind `this` so namespaced is working correctly - for (const name of Object.getOwnPropertyNames(SystemModule.prototype)) { + for (const name of Object.getOwnPropertyNames( + SystemModule.prototype + ) as Array) { if (name === 'constructor' || typeof this[name] !== 'function') { continue; } diff --git a/src/modules/vehicle/index.ts b/src/modules/vehicle/index.ts index 9c9841b0..2b153c79 100644 --- a/src/modules/vehicle/index.ts +++ b/src/modules/vehicle/index.ts @@ -6,7 +6,9 @@ import type { Faker } from '../..'; export class VehicleModule { constructor(private readonly faker: Faker) { // Bind `this` so namespaced is working correctly - for (const name of Object.getOwnPropertyNames(VehicleModule.prototype)) { + for (const name of Object.getOwnPropertyNames( + VehicleModule.prototype + ) as Array) { if (name === 'constructor' || typeof this[name] !== 'function') { continue; } diff --git a/src/modules/word/index.ts b/src/modules/word/index.ts index 5548e74f..614c6a59 100644 --- a/src/modules/word/index.ts +++ b/src/modules/word/index.ts @@ -8,7 +8,9 @@ import { filterWordListByLength } from './filterWordListByLength'; export class WordModule { constructor(private readonly faker: Faker) { // Bind `this` so namespaced is working correctly - for (const name of Object.getOwnPropertyNames(WordModule.prototype)) { + for (const name of Object.getOwnPropertyNames( + WordModule.prototype + ) as Array) { if (name === 'constructor' || typeof this[name] !== 'function') { continue; } diff --git a/src/utils/types.ts b/src/utils/types.ts index 012ad58b..afc4c17a 100644 --- a/src/utils/types.ts +++ b/src/utils/types.ts @@ -8,11 +8,16 @@ export type LiteralUnion = | (U & { zz_IGNORE_ME?: never }); /** - * Basically a function that returns a value. + * A function that returns a value. * - * For some strange reason this is not the same as `Function`. + * `Function` cannot be used instead because it doesn't accept class declarations. + * These would fail when invoked since they are invoked without the `new` keyword. */ -export type Callable = (...args) => unknown; +export type Callable = ( + // TODO christopher 2023-02-14: This `any` type can be fixed by anyone if they want to. + // eslint-disable-next-line @typescript-eslint/no-explicit-any + ...args: any[] +) => unknown; /** * Type that represents a single method/function name of the given type. -- cgit v1.2.3