pimbrouwers / Validus

An extensible F# validation library.
Apache License 2.0
144 stars 10 forks source link

Getting error in custom validator - Validators.Default.String.pattern #4

Closed AnalyzeNCode closed 3 years ago

AnalyzeNCode commented 3 years ago

I was just trying the sample of custom validator from the document but getting following compile time error. Am I missing anything?

image

pimbrouwers commented 3 years ago

Hi Subhash!

Thank you for reaching out. Sorry for the trouble. It appears you're missing the operators import to support the usage of <+>. If you add open Validus.Operators to your imports, it should work!

AnalyzeNCode commented 3 years ago

Oh, it's silly mistake by me. I have open the operators and the error has resolved. @pimbrouwers Thanks for the quick response.

AnalyzeNCode commented 3 years ago

@pimbrouwers The IDE (VS Code with Ionide) showing error as mentioned below in screenshot but the program execute successfully.

image

Actually, I tried by reloading window and also by restarting the vscode but still the IDE level error is there.

It's not like an issue in validus but just wanted to point out.

Edited: By adding None after pattern string resolves the IDE error but it generates error at compile time. For ex. If the code is like, let emailValidator = Validators.Default.String.betweenLen 8 512 <+> Validators.Default.String.pattern "@" None

Then there is no error in IDE, but when compile, I am getting following error.

ValidusInbuiltValidators.fs(10,13): error FS0001: Type mismatch. Expecting a 'Validator' but given a 'string -> ValidationResult' The type 'string -> ValidationResult' does not match the type 'ValidationResult'

pimbrouwers commented 3 years ago

No problem at all my friend! That is very interesting. I will try and repro this in the afternoon when I have some free time.

Appreciate you troubleshooting with me!

pimbrouwers commented 3 years ago

Just tested this out in VS Code and it worked for me: image

In looking at your screenshots again, I see the problem. Your file extension is .fs but should be .fsx.

AnalyzeNCode commented 3 years ago

I execute code by selecting and then Alt+Enter. I don't know the difference between both approach. Like, code in .fs file and code in .fsx. But I will try the in .fsx as well.

My most of experience is in C# and have just recently start programming in F# so don't have much idea about these concepts.

AnalyzeNCode commented 3 years ago

I have checked in .fsx and it's working. Thanks.