https://github.com/aleclarson/type-error
Expected ___, got ___ (~1 kb)
https://github.com/aleclarson/type-error
error error-messages
Last synced: 24 days ago
JSON representation
Expected ___, got ___ (~1 kb)
- Host: GitHub
- URL: https://github.com/aleclarson/type-error
- Owner: aleclarson
- License: mit
- Created: 2018-07-26T20:04:33.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-12-15T09:41:43.000Z (over 7 years ago)
- Last Synced: 2025-11-27T11:59:19.368Z (6 months ago)
- Topics: error, error-messages
- Language: JavaScript
- Homepage:
- Size: 4.88 KB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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.
```js
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.
```js
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'
```