gristlabs/ts-interface-checker

Get array of errors

victorKochkarev opened this issue · 5 comments

[Feature]
Right now validate method returns the first error that it will detect.
Is there a way to return all validation errors as an array of error objects?

No, unfortunately. The implementation is based on the early-exit approach, to keep it as fast as possible for the "fast" mode (to just return true/false for if a value is valid). To change that would require a non-trivial refactoring.

I would like to try to implement in a separate method.

This looks similar to #3

The implementation is based on the early-exit approach, to keep it as fast as possible for the "fast" mode (to just return true/false for if a value is valid)

Superstruct uses Iterators to work in either mode ("fail fast mode" or "complete error report mode"). Each node to be validated has an iterator of errors. When validation is called, it tries to get the first error from the root node error iterator. If there is a first error, it includes a method the user can call to complete the (recursive) iteration and get the full list of errors.

Pretty great idea to have the best of both worlds, if you ask me!

I'm not really sure about the internals of this library, but it might even be a relatively simple refactor, if all the validation-error-returning functions can be turned into validation-error-iterating generator functions.

v1.0 now returns multiple errors from validate() (#47) so I think this can be closed.