From 2b15f2ee7eeba7147c75a24d71042ee996966c92 Mon Sep 17 00:00:00 2001 From: pomali Date: Sun, 3 Mar 2024 11:12:17 +0100 Subject: feat(helpers)!: stricter checking for function signature passed to `multiple` (#2563) Co-authored-by: ST-DDT Co-authored-by: Matt Mayer <152770+matthewmayer@users.noreply.github.com> --- src/modules/helpers/index.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src/modules') diff --git a/src/modules/helpers/index.ts b/src/modules/helpers/index.ts index 593d1ede..b21f13e7 100644 --- a/src/modules/helpers/index.ts +++ b/src/modules/helpers/index.ts @@ -1129,17 +1129,19 @@ export class SimpleHelpersModule extends SimpleModuleBase { * @template TResult The type of elements. * * @param method The method used to generate the values. + * The method will be called with `(_, index)`, to allow using the index in the generated value e.g. as id. * @param options The optional options object. * @param options.count The number or range of elements to generate. Defaults to `3`. * * @example - * faker.helpers.multiple(faker.person.firstName) // [ 'Aniya', 'Norval', 'Dallin' ] - * faker.helpers.multiple(faker.person.firstName, { count: 3 }) // [ 'Santos', 'Lavinia', 'Lavinia' ] + * faker.helpers.multiple(() => faker.person.firstName()) // [ 'Aniya', 'Norval', 'Dallin' ] + * faker.helpers.multiple(() => faker.person.firstName(), { count: 3 }) // [ 'Santos', 'Lavinia', 'Lavinia' ] + * faker.helpers.multiple((_, i) => `${faker.color.human()}-${i + 1}`) // [ 'orange-1', 'orchid-2', 'sky blue-3' ] * * @since 8.0.0 */ multiple( - method: () => TResult, + method: (v: unknown, index: number) => TResult, options: { /** * The number or range of elements to generate. -- cgit v1.2.3