-
Notifications
You must be signed in to change notification settings - Fork 0
Custom
iamchenxin edited this page Jun 6, 2016
·
4 revisions
assume you want to valid some name:
// custom caster . note:
//this do not validate a literal,just a custom dynamic type you defined
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
}
}