# type-error

> Create native TypeError objects from an expected type and actual value

Latest version **1.0.3** (published 2018-08-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install type-error
pnpm add type-error
yarn add type-error
bun add type-error
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.3 |
| Published | 2018-08-14 |
| First published | 2018-07-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 3.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Maintainers | aleclarson |

## Links

- npm: https://www.npmjs.com/package/type-error
- Repository: https://github.com/aleclarson/type-error
- Homepage: https://github.com/aleclarson/type-error#readme
- Issues: https://github.com/aleclarson/type-error/issues
- npm.io page: https://npm.io/package/type-error

## Recent versions

- 1.0.3 (latest) — 2018-08-14
- 1.0.2 — 2018-07-27
- 1.0.1 — 2018-07-27
- 1.0.0 — 2018-07-27

## 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'
```

---
_Source: https://npm.io/package/type-error · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
