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
Validate arguments and result of functions call for good guaranties of code correctness.
Automatically generate documentation.
Infer static types.
SSoT of validators, static types and documentation.
[static] Refinement data-types
Leave mocks for tests (generate it automatically).
Property-base testing out of the box.
[target] Example
import*astfrom'rtcad'import*asnetworkfrom'./network'// fetcher// declare runtypeconstPassword=t.String()// declare runtype with description and extended validationconstEmail=t` simple e-mail validation${t.String(value=>value.contains('@'))}`// declare structureconstUser=t`user data ${t.Record({id: t.Number(),name: t.String(),avatar: t.OR(t.Null,t.String(url=>url.startsWith('http'))),})}`// declare ~generic by custom runtype// (TypeScript syntax)constInstanceof=<Textendst.Runtype>(Gen: T)=>t.custom<T>(value=>valueinstanceofGen)// use genericconstErrorApi=Instanceof(network.Error)// declare contract for function with description (Markdown)exportconstauthUser=t` # Return detailed user data from auth service > set auth token to cookies - ${[Email,Password]} - ${t.Promise(User,ErrorApi)}`((email,password)=>network.get(`/user`,{ email, password }))/* EQUAL */// declare contract for function without descriptionexportconstauthUser=t([Email,Password],t.Promise(User,ErrorApi))((email,password)=>network.get(`/user`,{ email, password }),)/** * Now we can: * 1. Infer static types. * 2. Validate arguments and result of `authUser` call. * 3. Automatically generate documentation. * 4. Leave mocks for tests (generate it automatically). * 5. Property-base testing out of the box. */