-
-
Notifications
You must be signed in to change notification settings - Fork 929
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
refactor(helpers)!: remove default value from arrayElement #2045
refactor(helpers)!: remove default value from arrayElement #2045
Conversation
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## next #2045 +/- ##
=======================================
Coverage 99.61% 99.61%
=======================================
Files 2535 2535
Lines 242221 242231 +10
Branches 1291 1299 +8
=======================================
+ Hits 241283 241303 +20
+ Misses 911 901 -10
Partials 27 27
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
regression:
faker.helpers.arrayElement(["foo","bar",undefined])
now throws an error 1/3 of the time.
Or we simply check the array length on input and throw? Why get that complex...^^ If someone provides an array with |
Because of faker/src/modules/helpers/index.ts Lines 801 to 803 in 99c16e4
|
can't you just change the condition for throwing from const value = array[index];
if (value === undefined) {
throw new FakerError('Cannot get value from empty set.');
} to if (array.length === 0) {
throw new FakerError('Cannot get value from empty set.');
}
const value = array[index]; |
To clarify, in Faker 7, the behavior was:
Do we want it to now throw in both these cases (array is empty, array is undefined)? |
Yes and no. This is precisely what I was stating in my previous comment. But we have to keep in n mind that this will cause trouble in later versions if we decide to activate more strict typescript features. I'm talking about the noUncheckedIndexedAccess rule.
Yes, we do want that. |
Whether or not it makes sense, passing an undefined array happens in existing places in the code at the moment and ends up with "b". We should add tests for various cases: Undefined array |
I highly assume that this is the reason why this PR is in "draft", but thanks for also thinking about it 🙂 |
Co-authored-by: Shinigami <chrissi92@hotmail.de>
Co-authored-by: Eric Cheng <ericcheng9316@gmail.com>
please review again or approve
@Shinigami92 we are not in a hurry. |
This was not related with being in a hurry in any case?! |
Then please wait with dismissing their review, so they actually have time to review again. |
Closes #219.