Validation type of value is assignable.
$ npm install --save v-type
const vType = require('v-type');
vType('△', String);
//=> true
vType(['△'], String);
//=> TypeError: Type `Array` is not assignable to type `String`
Returns throw TypeError
if input
is not assignable to type TypeName
.
Required: true
Type: any
Required: true
Type: constructor<Function>
The constructor function - Function
, Object
, Array
, Map
, etc...
Type: string
Set the default message.
Example:
function foo(bar) {
vType(bar, Object, 'Expected `bar` to be of type `Object`');
console.log(bar.x);
}
foo({x: 'yo'});
//=> 'yo'
foo('1');
//=> 'TypeError: Expected `bar` to be of type `Object`'
MIT © Guntur Poetra