Skip to content

Commit ac8724d

Browse files
committed
docs: write upgrading guide
1 parent 53ec712 commit ac8724d

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

docs/guide/upgrading_v9/2563.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
### Expose signature parameters in `method` parameter of `faker.helpers.multiple`
2+
3+
We now expose the parameters from the `method` parameter to our users.
4+
That allows for usecases where the index is part of the generated data e.g. as id.
5+
6+
```ts
7+
faker.helpers.multiple((_, index) => ({ id: index, ...}), ...); // [{id: 0, ...}, ...]
8+
```
9+
10+
While the actual implementation of the method hasn't changed, it's signature has.
11+
Previously it was possible to incorrectly pass any function reference to `faker.helpers.multiple`,
12+
even those that are incompatible with the actual parameters passed to the generator function.
13+
This change causes compile time errors only in cases that would otherwise be potential runtime errors.
14+
15+
**Bad**
16+
17+
```ts
18+
faker.helpers.multiple(faker.person.firstName, ...); //
19+
// Argument of type '(sex?: "female" | "male" | undefined) => string'
20+
// is not assignable to parameter of type '(v: unknown, index: number) => unknown'.
21+
```
22+
23+
**Good**
24+
25+
```ts
26+
faker.helpers.multiple(() => faker.person.firstName(), ...); //
27+
```

0 commit comments

Comments
 (0)