typesafe-is
TypeScript icon, indicating that this package has built-in type declarations

1.1.3 • Public • Published

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.

Dependents (0)

Package Sidebar

Install

npm i typesafe-is

Weekly Downloads

8

Version

1.1.3

License

MIT

Unpacked Size

10 kB

Total Files

10

Last publish

Collaborators

  • malcolmkee