You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using inSequence and changing the type of the input value with a validator, the types suggests that the following validator will receive the updated input value but this is not true, as the return of the validator just gets discarded, from what I can see on the implementation and the function type this shouldn't work like this.
validators.inSequence(validators.validator<string,number,string>((input)=>{constnewInput=parseFloat(input);returnNumber.isNaN(newInput) ? success(newInput) : failure("Invalid number");}),validators.fromPredicate((input)=>Number.isFinite(input),"Number is not finite"),)
For an input of "100" I would expect the validation to success, but instead it fails on the second validator as input is "100" (string) instead of 100 (number).
The problem seems to be with this line input = r.success;, I suppose it should be value = r.success; so that the next validation will receive the updated input.
@pedrodim indeed it looks like a bug, and I believe your proposed solution is fine. Would you mind submitting a PR? I would also like to add a test for this, such as (or a better one, I made this up in a few minutes):
describe("validators",()=>{describe("inSequence",()=>{test("should pass the validation output to the subsequent one",async()=>{constv1=validators.validator((a: string)=>success(a.length));constf=jest.fn((b: number)=>success(b));constv2=validators.validator(f);awaitvalidators.inSequence(v1,v2)("foo");expect(f).toHaveBeenCalledWith(3);});});});
When using
inSequence
and changing the type of the input value with a validator, the types suggests that the following validator will receive the updated input value but this is not true, as the return of the validator just gets discarded, from what I can see on the implementation and the function type this shouldn't work like this.For an input of
"100"
I would expect the validation to success, but instead it fails on the second validator asinput
is"100"
(string) instead of100
(number).The problem seems to be with this line
input = r.success;
, I suppose it should bevalue = r.success;
so that the next validation will receive the updated input.formo/src/validators.ts
Lines 90 to 97 in 5fdd851
The text was updated successfully, but these errors were encountered: