Conversation
|
@kamijin-fanta this is cool! A few ideas...
Which would make a Struct<number, null, {
type: 'number'
} | {
refinement: 'min'
min: 0,
exclusive: false
}>And type Failure<E extends Record<string, any>> = {
value: any
key: any
branch: Array<any>
path: Array<any>
message: string
} & E |
|
@ianstormtaylor Thanks for the idea! The reason I made I work on a Failure type change. |
|
Do you have any idea for the definition of toFailure, Result and Validator when rewriting to export type Result<E extends Record<string, any>> =
| boolean
| string
| Partial<Failure<E>>
| Iterable<boolean | string | Partial<Failure<E>>>It may be possible to solve it by redefining the Result type as follows. export type DescribedResult<E extends Record<string, any>> =
| boolean
| string
| Partial<Failure<E>>
| Iterable<boolean | string | Partial<Failure<E>>>
export type SimpleResult = boolean | string | Iterable<boolean | string>
export function define<T>(
name: string,
validator: SimpleValidator
): Struct<T, null, {}>;Also, it can be easily implemented by giving up the type definition for detailed error information. Of course I want to avoid this if possible. |
|
@kamijin-fanta good question! I tried messing with it in the TypeScript Playground and came up with this approach which may help? It keeps a "props" dictionary as the third argument which then determines which "results" are allowed to be returned by a validation function. I wasn't sure how to limit it more than |
|
Hi, what's the status for this PR? |
|
@xiaoyu-tamu sorry. I couldn't get enough time and left it. I would like to work on it when other work is done, but I would like to welcome other people's contributions. |
|
Maybe the maintainers would consider taking this code in and continuing on it? |
ref #568
A design proposal for structurally expressing errors. This PR makes it possible to support custom error messages and i18n. This library will be available for displaying errors to users.
For example,
size(string(), 1, 100)outputs the error message${expected} with a length ${of} but received one with a length of ' ${length}'. This change outputs the following error content in addition to the message. It is possible to format the error message according to the context and language.