-
-
Notifications
You must be signed in to change notification settings - Fork 118
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
randSequence with charsType pattern #258
Conversation
packages/falso/src/lib/sequence.ts
Outdated
@@ -43,11 +41,33 @@ type RandomSequenceOptions = { | |||
* | |||
* @example | |||
* | |||
* randSequence({ charType: 'numeric' }) // numeric | alpha | alphaNumeric (can't be used with 'chars' parameter ) |
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.
We can remove (can't be used with 'chars' parameter )
and enforce by using type overloading.
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.
Ok, I can remove comment, but charType
only works if chars
not specified. If chars
specified, chars
got highest priority.
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.
If using both doesn't make sense we can enforce it using typescript
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.
If using both doesn't make sense we can enforce it using typescript
OK, if I understand you right, I can create another charType
with name custom
and enforce user to specify chars
, otherwise throw error, when chars specified without charType
custom
but it's breaking change I think
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.
type RandomSequenceOptions = {
size?: number;
chars?: string;
}
type RandomSequenceOptions2 = {
size?: number;
charType?: 'numeric' | 'alpha' | 'alphaNumeric';
}
function foo(options: RandomSequenceOptions): any;
function foo(options: RandomSequenceOptions2): any;
function foo(options: any) {}
foo({charType: 'alphaNumeric', chars: ''}) // error
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.
@NetanelBasal OK, I prepare commit soon
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.
@NetanelBasal looks like if I use that code, I really get typescript error, when trying to use wrong method signature, but I lost types because types returned using internal Return<string, Options>
, can I expose that Return
type via export
?
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
fix flaky test check for
random-float
What is the current behavior?
Issue Number: N/A
What is the new behavior?
randSequence
can generate sequence via predefined char patterns:alpha
[Aa-Zz]numeric
[0-9]alphaNumeric
[Aa-Zz0-9]Does this PR introduce a breaking change?
Other information