-
Notifications
You must be signed in to change notification settings - Fork 7
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
Machine-readable errors #8
Comments
So, you can pass the option Then, the expected value will be the "type IR" that is expected at that location. The path where the error occurs should be relatively easy to parse into an object format, if you choose (all object keys are quoted, array keys are unquoted numbers), it always starts with input. Let me know if any other functionality would be useful in this regard. Also can you post the type you are validating? I should fix this duplicated groups bug. This error message functionality is pretty new (although I did write a bunch of tests!), so it's really helpful if whenever you encounter a bug in the error messages, if you report it with the type in question. (There shouldn't be many/any bugs though!) |
@vedantroy Okay, I'll try to get something working with that 🙂 The relevant part of my type should be the following: type Quiz = {
groups: { [key: string]: string; };
} |
Hmm... I'll take a look at this. It would also be helpful to have a bit more detail about what you want from the error messages. I think you can convert the path into a nested JSON object, so I assume that's not the issue. The actual value will always remain as the actual value, so I assume that's not an issue either. Is there an issue with the current string representation of the expected type? It seems like in your envisioned scenario, the expected type would be still be represented as a string. Do you want the string representation to more closely match Typescript's type signatures? It seems to me like the current string representation of the type provides as much detail as a normal typescript type signature. |
@vedantroy No worries - I'll try to see what I can get from the current data and let you know if there are any issues or further feature requests 🙂 I do have a few different use cases I'm trying to solve right now:
But overall, I'm happy with how the validation works already - nice job! 🏆 |
Thanks for the new error messages functionality, it's a big improvement over just
false
😁However actually trying to use the returned values is a bit inconvenient (beyond just dumping them to console or outputting them somewhere as-is) 😅
I am trying to generate something like a "diff", to highlight places where the validation failed in the input - so ideally I would need something like a structured representation of where the problems are, and then the raw expected type.
Instead of this:
I would like to get:
The structure transformation could be done afterwards, splitting the
path
string and transforming it into an object-structure or something. Maybe I could also generate type-definition strings from the IR if I request that as the return value (is that possible from the data we still have in that representation?)The text was updated successfully, but these errors were encountered: