typesafe-is
v1.1.3
Published
Check the type of a value with typescript typeguard
Downloads
5
Maintainers
Readme
typesafe-is
Example
import { isString } from 'typesafe-is';
let x: string | number;
if (isString(x)) {
console.log(x.subtr(1)); // Error, 'subtr' does not exist on `string`
console.log(x.substr(1)); // OK
} else {
console.log(x.substr(1)); // Error
console.log(x.subtr(1)); // OK, 'subtr' exists on number
}
Installation
This module is distributed via npm which is bundled with node and
should be installed as one of your project's dependencies
:
npm install --save typesafe-is
or
yarn add typesafe-is
API
All functions can be imported with one of the following statements:
import { isNil } from 'typesafe-is'; // this works
const { isNil } = require('typesafe-is'); // this works too
See here for full list of available typechecking functions.