From ac8724dc6eebd705596120c2870fc065176057e4 Mon Sep 17 00:00:00 2001 From: ST-DDT Date: Sat, 2 Mar 2024 00:37:10 +0100 Subject: [PATCH] docs: write upgrading guide --- docs/guide/upgrading_v9/2563.md | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 docs/guide/upgrading_v9/2563.md diff --git a/docs/guide/upgrading_v9/2563.md b/docs/guide/upgrading_v9/2563.md new file mode 100644 index 00000000000..6b89fb3d186 --- /dev/null +++ b/docs/guide/upgrading_v9/2563.md @@ -0,0 +1,27 @@ +### Expose signature parameters in `method` parameter of `faker.helpers.multiple` + +We now expose the parameters from the `method` parameter to our users. +That allows for usecases where the index is part of the generated data e.g. as id. + +```ts +faker.helpers.multiple((_, index) => ({ id: index, ...}), ...); // [{id: 0, ...}, ...] +``` + +While the actual implementation of the method hasn't changed, it's signature has. +Previously it was possible to incorrectly pass any function reference to `faker.helpers.multiple`, +even those that are incompatible with the actual parameters passed to the generator function. +This change causes compile time errors only in cases that would otherwise be potential runtime errors. + +**Bad** + +```ts +faker.helpers.multiple(faker.person.firstName, ...); // ❗ +// Argument of type '(sex?: "female" | "male" | undefined) => string' +// is not assignable to parameter of type '(v: unknown, index: number) => unknown'. +``` + +**Good** + +```ts +faker.helpers.multiple(() => faker.person.firstName(), ...); // ✔ +```