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
{{ message }}
This repository was archived by the owner on Mar 29, 2025. It is now read-only.
As we know, runtype only tells you if an type-check passed or not, and doesn't tell why it failed. This proposal outlines the new API for validation messages.
Description
Currently, Predicate is a function that takes x and guards it against a type. This proposal recommends the addition of a validate method to Predicate which returns the following type:
Where ValidationError extends Error with the properties expected and actual describing the corresponding types as string to produce a nicer error; and by default .message describing a generated error.
Example:
constMessage=struct({from: string,to: string,content: string});// elsewhereconstres=Message.validate(msg);if(res.ok){// use msg}else{// res.error}
Downsides:
res.ok doesn't actually guard msg, and you get no static types like you normally would with the type guard.