-
-
Notifications
You must be signed in to change notification settings - Fork 949
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
Typing of gender conflicts with common usage patterns #776
Comments
Attention: Instead of using But then you should start think about why using this in the first place 🤔 So use functions like faker.name.firstName(); // Just return me a name
faker.name.firstName('female'); // I specifically target female (e.g. for a shop?)
faker.name.firstName('male'); // I specifically target male (e.g. for a shop?) What we could do is to provide a helper function like |
I think this has nothing to do with being exclusive, this is just how forms in the web work. However, you pointed out correctly that the
IMO we should provide it, to allow the user to generate consistent data. In your head it should look like this: const gender = genderType();
const firstName = firstName(gender);
const lastName = lastName(gender); and not like in your example: const gender = 'female';
const firstName = firstName('female');
const lastName = lastName('female'); Maybe to remove the current implementation bias from your/everyones head, we could add a That being said, I would like to strictly limit the IMO the
For consistency we should add a way to map the gender type to a gender locale value. TLDR:
|
Also some good point. I would not expect that a user's html form matches the API of faker and therefore they already need to write their mapper to be compatible to our API. So I would not like to assume that it should be just designed in that way. I also wont like to expose a usable parameter like faker.locale = 'de'
faker.name.firstName() // 'Gisela' or 'Herbert' or 'Toni'
faker.name.firstName('female') // 'Gisela'
faker.name.firstName('male') // 'Herbert'
faker.name.firstName('non-binary') // 'Toni' So if we implement a function like |
I just found out that it is possible to execute the following code: import { Gender } from '@faker-js/faker'
const genders = Object.values(Gender);
const randomGender = faker.random.objectElement(Gender);
faker.name.firstName(genders[0]); // works
faker.name.firstName(randomGender); // works |
After consulting with @Shinigami92 , I think we should call the new value type GenderType = 'any' | 'female' | 'male';
genderType(onlyBinary: boolean = false): GenderType;
firstName(gender: GenderType = 'any') This also allows more explicit calls like |
We could also provide |
We had a HUGE internal and long conversation and we may want to switch We are also currently asking in some communities for feedback and so it could take a while until we proceed further with stuff around Edit: Reference-Link: https://twitter.com/_jessicasachs/status/1511375258548379662 |
@Shinigami92 I dont consider this fixed yet. |
Fixed by #1289 |
Describe the bug
Although in practice
faker.name.firstName
et al. can accept any value, their typing limits them toGenderType | undefined
, which is currently'female' | 'male' | 0 | 1 | undefined
. The specific problem with this is that you can't use the return value fromfaker.name.gender()
, whether or not you setbinary
totrue
, as the argument to the other methods.Reproduction
This works fine in JavaScript:
but the exact same code in TypeScript gives:
Additional Info
I found out about this via a Stack Overflow question: https://stackoverflow.com/q/71743871/3001761
The text was updated successfully, but these errors were encountered: