feat(helpers): allow using parameters in `method` param of `multiple`
faker.helpers.multiple() supports using mapFn like in Array.from(), but type signature of function didn't match, PR fixes this and adds test for this case
(but since it changes declared interface I chose feat instead of fix as semantic type)
I'm not sure if this fits the use case of faker.helpers.multiple :thinking:
If you require the parameters of the mal function, you are most likely doing some static value generation.
I need some time to think about this in more detail.
Yes, usecase here is generating two sets of objects with matching ids, so I can "join" them later. Eg.
interface School { locationId: number }
interface Location { id: number }
I could create an function with no arguments that simulates this behavior, but it seemed busywork since underlying code already supports it.
I am using it in place without shared state (in mock service worker in two different endpoints)
Codecov Report
All modified and coverable lines are covered by tests :white_check_mark:
Project coverage is 99.56%. Comparing base (
9348138) to head (529aac6).
Additional details and impacted files
@@ Coverage Diff @@
## next #2563 +/- ##
==========================================
- Coverage 99.57% 99.56% -0.02%
==========================================
Files 2846 2846
Lines 248715 248717 +2
Branches 655 1011 +356
==========================================
- Hits 247669 247634 -35
- Misses 1017 1083 +66
+ Partials 29 0 -29
| Files | Coverage Δ | |
|---|---|---|
| src/modules/helpers/index.ts | 98.82% <100.00%> (+<0.01%) |
:arrow_up: |
Sorry for the delay in feedback. Could you please update this PR with the latest suggestions?
Sorry for the delay in feedback. Could you please update this PR with the latest suggestions?
No problem, sorry for mine delay. Updated.
Could you please fix the broken tests and examples? The tests were already broken due to the wrong typing of the method before, but now the method actually requires proper types and thus the bad usage actually shows up.
firstName -> () -> firstName()
Please also enable allow edits by maintainers on this PR so we can update it ourself to the latest commits on next.
Do we consider this breaking?
Because previously you could incorrectly pass any function reference directly to the method even, if it would be called with garbage values, so it is kind of a bugfix, but one that prevents you from doing bad things.
Do we consider this breaking?
I think it's better to mark it as breaking as not doing it and then it was breaking