Open lukasluecke opened 4 years ago
So, you can pass the option expectedValueAsIR
with the value true
to createDetailedValidator
.
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:
{ [key: string]: string; }
instead of "object↵ where all keys are: ↵ type: string"
)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?)