-
-
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
faker.lorem.word
can return undefined
despite being typed as string
#1131
Comments
What is your expected behavior?
EDIT: We could introduce two signatures for those methods though. One without |
I think i would personally expect it to be typed as Getting a word with a different length when explicitly specifying a length seems like it'd be more troublesome, and having a function suddenly able to throw errors while other faker functions don't do so doesn't seem like a good idea either imo. Splitting it up into separate methods like you suggested seems reasonable. EDIT: Alternatively, we could use conditional types to return either |
Could the function be made such that if you pass in a length that's greater than any word, it caps the value to the max word length? The few times I've used this function in the past, it was being passed into a function or whatever that doesn't allow undefined, and adding |
What about shorter words e.g. length = 1? |
|
In #1218 I implemented it in a way that if a user expects too long word, the maximum possible length is given. |
Team decision
Further discussions
|
Note since we need this in multiple modules this should be done in a new central method: |
Note2 it should be applies/used for all of our word methods (those with a length parameters) in a single PR. |
Just to raise my voice because I suffer in silence: I would suggest to name it strategy instead of errorHandling |
OK.
Or |
What about just |
Describe the bug
When calling
faker.lorem.word
with a length that doesn't have any matching words, it will returnundefined
while TypeScript thinks it's astring
.Reproduction
Additional Info
No response
The text was updated successfully, but these errors were encountered: