-
-
Notifications
You must be signed in to change notification settings - Fork 944
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
27 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(), ...); // ✔ | ||
``` |