Skip to content

fix(helpers): multiple update argument types #2636

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

rtm-ctrlz
Copy link

@rtm-ctrlz rtm-ctrlz commented Jan 31, 2024

With this change users of faker.helpers.multiple() will know that method function may have access to index of current element.

Use case: generator wants to know the index of element that it is generating.

This is not a breaking change, because it add argument types for already used code, any current code that is using this function will work without any changes/warnings. But in future it may lead to some difficulties with changing method signature or refactoring inner code (Array.from). There is a way to mitigate this issue but it requires to modify Array.from call will additional wrapper-function, that will negotiate method definition with actual used code.

pnpm run preflight runs without errors.

Usage example:

// case: create array of negative numbers
const value = faker.helpers.multiple((_, index) => -1 - index);
// value = [ -1, -2, -3 ]

// case: create array of objects {id: number}, with ids 100, 200, 300
const value = faker.helpers.multiple((_, index) => ({id: (index+1) *100}));
// value = [ { id: 100 }, { id: 200 }, { id: 300 } ]

…pers.multiple`

With this change users of `faker.helpers.multiple` will know that `method` function may have access to `index` of current element.
@rtm-ctrlz rtm-ctrlz requested a review from a team as a code owner January 31, 2024 17:29
@ST-DDT
Copy link
Member

ST-DDT commented Jan 31, 2024

Potential duplicate of: #2563

Copy link

codecov bot commented Jan 31, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (8ccc49d) 99.57% compared to head (16c4dd8) 99.57%.

Additional details and impacted files
@@            Coverage Diff             @@
##             next    #2636      +/-   ##
==========================================
- Coverage   99.57%   99.57%   -0.01%     
==========================================
  Files        2807     2807              
  Lines      250452   250452              
  Branches     1150     1152       +2     
==========================================
- Hits       249388   249386       -2     
- Misses       1036     1038       +2     
  Partials       28       28              
Files Coverage Δ
src/modules/helpers/index.ts 98.98% <100.00%> (ø)

... and 2 files with indirect coverage changes

@rtm-ctrlz
Copy link
Author

@ST-DDT yes, it is duplicate. That PR also have tests that covers usage of function this way.

Can't understand how I missed it when I was doing pre-PR checks.

@ST-DDT ST-DDT added c: feature Request for new feature p: 1-normal Nothing urgent m: helpers Something is referring to the helpers module s: on hold Blocked by something or frozen to avoid conflicts labels Jan 31, 2024
@ST-DDT
Copy link
Member

ST-DDT commented Feb 1, 2024

Closing as duplicate of #2563

Thanks for your contribution anyway.

@ST-DDT ST-DDT closed this Feb 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: feature Request for new feature m: helpers Something is referring to the helpers module p: 1-normal Nothing urgent s: on hold Blocked by something or frozen to avoid conflicts
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants