New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

type-error

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

type-error

Create native TypeError objects from an expected type and actual value

1.0.3
latest
Source
npm
Version published
Maintainers
1
Created
Source

type-error v1.0.3

Create a native TypeError object by passing the expected type and the actual value.

Note: No validation is done; only type & value formatting.

const TypeError = require('type-error');

const foo = new Foo();
if (!(foo instanceof Bar)) {
  throw TypeError(Bar, foo); // 'Expected a Bar instance, got a Foo instance'
}

The first argument should be the constructor of the expected type, or a string describing the expected value. The second argument can be anything.

TypeError(Function, 1)      // 'Expected a function, got a number'
TypeError(Array, true)      // 'Expected an array, got true'
TypeError(Number, NaN)      // 'Expected a number, got NaN'
TypeError('null', {})       // 'Expected null, got an object'

FAQs

Package last updated on 14 Aug 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts