Skip to content
iamchenxin edited this page Jun 4, 2016 · 4 revisions

How to write custom validator.

assume you want to valid some name: // custom caster . function isTom(v:mixed):string { const str = isString(v); // appropriate parent type, Tom's name should be string if ( v === 'Tom' ){ return str; // check pass -> return str } else { throw new Error('is not Tom'); // check failed -> throw } }

Clone this wiki locally