You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
However, if the user adds their own parsers, they might also want to add their own custom errors that adhere to a different format. For example, they might want to include a different type of path segment that points to an index within a string:
{tag: 'string',index: number}
However, as it stands, they're limited to tags object and array. According to this proposal, the path and error properties should be removed from the library and replaced by a new property error:
(The type parameter should be optional, so that you can write just Parse<?>.)
The higher order parsers should infer the types of the error messages, just as they infer the type parameter Value. So you could end up with a nested error that describes all possible failure outcomes; for example, for parsing an object with two properties a: number and b: string:
We could provide function for converting this to a JSON path.
This would work when inferring types, but for explicit type declarations, this would become extremely unergonomic: since TypeScript does not implement partial type inference, the user would need to also specify the second type argument
Cons:
It will make the API more complicated, thus making it more complicated to extend; especially for higher order parsers. As a compromise, we could provide a default value as the second type parameter GeneralError which allows the user to bypass the complex error handling logic.
The size of the error grows with the size of the object.
Lots of work (but doable), but I don't know if anyone would use this feature.
Questions:
How are recursive types handled?
Will anyone ever be interested in the improved errors?
The text was updated successfully, but these errors were encountered:
Note
This feature is blocked because TypeScript needs to support partial type inference:
#70 introduces a path in the error message which allows you to see where the parsing error occurred.
Which means that
data.a[0]
failed to parse.However, if the user adds their own parsers, they might also want to add their own custom errors that adhere to a different format. For example, they might want to include a different type of path segment that points to an index within a string:
However, as it stands, they're limited to tags
object
andarray
. According to this proposal, thepath
anderror
properties should be removed from the library and replaced by a new propertyerror
:And:
(The type parameter should be optional, so that you can write just
Parse<?>
.)The higher order parsers should infer the types of the error messages, just as they infer the type parameter
Value
. So you could end up with a nested error that describes all possible failure outcomes; for example, for parsing an object with two propertiesa: number
andb: string
:Or maybe something more easy on the eye?
We could provide function for converting this to a JSON path.
This would work when inferring types, but for explicit type declarations, this would become extremely unergonomic: since TypeScript does not implement partial type inference, the user would need to also specify the second type argument
Cons:
GeneralError
which allows the user to bypass the complex error handling logic.Questions:
The text was updated successfully, but these errors were encountered: