项目作者: aleclarson

项目描述 :
Expected ___, got ___ (~1 kb)
高级语言: JavaScript
项目地址: git://github.com/aleclarson/type-error.git
创建时间: 2018-07-26T20:04:33Z
项目社区:https://github.com/aleclarson/type-error

开源协议:MIT License

下载


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.

  1. const TypeError = require('type-error');
  2. const foo = new Foo();
  3. if (!(foo instanceof Bar)) {
  4. throw TypeError(Bar, foo); // 'Expected a Bar instance, got a Foo instance'
  5. }

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

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