Skip to content
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

Ignore Methods not Supported or Support RegExp Validation #16

Open
FlorianWendelborn opened this Issue Mar 10, 2019 · 3 comments

Comments

Projects
None yet
2 participants
@FlorianWendelborn
Copy link

FlorianWendelborn commented Mar 10, 2019

I just tried to validate that one of my optional config variables is a RegExp. typescript-is complained and told me:

Error: Encountered a method declaration, but methods are not supported. Please check the README

Would it be possible to either support RegExp, or to opt-out of this error explicitly in the is<...>(...)?

@woutervh-

This comment has been minimized.

Copy link
Owner

woutervh- commented Mar 11, 2019

Hi @FlorianWendelborn

I understand you're trying to validate an object that has a RegExp type property.
Classes are not supported, and because RegExp is a class, it's also not supported.
That being said, I'm not sure why the error message is about a "method" and not a "class", this is something I will investigate.
I also think adding an option to ignore classes/methods/RegExp/Date etc. is a good idea.
So I will be adding the option to ignore those rather than throw an error.

Will keep you updated.

Thanks!

@woutervh-

This comment has been minimized.

Copy link
Owner

woutervh- commented Mar 11, 2019

Foot note 1: typescript-is mainly focuses on validation serializable data. Since a RegExp class is generated at runtime, it's somewhere in the code, and that means it should have a type. Is there a reason why the type is lost somewhere in your code?
Foot note 2: if the RegExp is encoded as a string then it becomes serializable and then typescript-is can check if it's a string.

@woutervh-

This comment has been minimized.

Copy link
Owner

woutervh- commented Mar 19, 2019

Hi @FlorianWendelborn

I've added the following options: ignoreClasses, ignoreMethods
The latter is needed for skipping RegExp validation.

Version: 0.10.2 0.10.3
Documentation: https://github.com/woutervh-/typescript-is#options

Let me know if this works for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.