Options
All
  • Public
  • Public/Protected
  • All
Menu

typesafe-is

typesafe-is

version license build Coverage Status

Typecheck and narrow down the variables/parameters with typeguard


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.

Generated using TypeDoc