To see its functionality demonstrated, take a look at [the tests](https://github.com/rauschma/type-right/blob/master/test/index_test.js).
npm install type-rightTo see its functionality demonstrated, take a look at the tests.
Installation:
``text`
npm install type-right
Importing:
`js`
import * as tr from 'type-right';
for primitive valuesHaving to choose between typeof and instanceof is annoying. TypeRight uses Symbol.hasInstance to fix this:
`js`
console.log('abc' instanceof tr.PrimitiveString); // true
console.log(null instanceof tr.PrimitiveNull); // true
`js`
tr.force('abc', tr.PrimitiveString); // ok
tr.force(undefined, tr.PrimitiveString); // TypeError
If parameters can be missing or undefined:
`js`
tr.force('abc', tr.union(tr.PrimitiveString, tr.PrimitiveUndefined)); // ok
tr.force(undefined, tr.union(tr.PrimitiveString, tr.PrimitiveUndefined)); // ok
`js``
function dist(x, y) {
tr.force(x, tr.PrimitiveNumber, y, tr.PrimitiveNumber);
return Math.hypot(x, y);
}