-
Notifications
You must be signed in to change notification settings - Fork 54
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
Check for string length and number range #207
Comments
How would the generator know what to generate for |
Yes the validator types would be exported by ts-auto-guard itself. |
It's an interesting idea, but I think out of scope for ts-auto-guard, unless it's possible to express those constraints via the type system itself, which apparently it is: https://stackoverflow.com/a/39495173/317135 https://stackoverflow.com/a/54832231/317135 However both of these look pretty hectic, it may not be worth the maintenance cost. |
Yes you are right that it is not in the scope of the "guard" system but a completely new feature, and I wanted to share it with you because you already made the logic of using static types and generating some code from them. This feature would reuse the same logic, the only difference will the generated code I think. |
It looks as though something like this is possible via static types, and it would be cool to support it with type guards, but given the amount of active support this project receives I don't want to expand its feature set. You're of course welcome to take whatever you like from the code base to make a similar project though, and I see that it could be useful. I'll leave this issue open in case someone wants to have a shot at handling these type constraints that are possible in TS. |
Really appreciate the possibility to use typescript interface to generate runtime code.
And also it is very nice to be able to use the typescript interfaces as it is, not having to rewrite them into library-dependant code.
This being said, one other feature that could be very useful is to have validators also generated.
Here is a code sample to give ideas:
The interfaces MinLength, MaxLength, Min, Max (and others) would be exported by ts-auto-guard, the generator will use these types to generate
validateUser
.The text was updated successfully, but these errors were encountered: