Skip to content

Commit

Permalink
docs: write upgrading guide
Browse files Browse the repository at this point in the history
  • Loading branch information
ST-DDT committed Mar 1, 2024
1 parent 53ec712 commit ac8724d
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions docs/guide/upgrading_v9/2563.md
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(), ...); //
```

0 comments on commit ac8724d

Please sign in to comment.