Skip to content

Commit

Permalink
Refactor TypeScript definition to CommonJS compatible export (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
BendingBender authored and sindresorhus committed Apr 5, 2019
1 parent 19b4e7e commit 4019dd8
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 9 deletions.
36 changes: 32 additions & 4 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,32 @@
/**
* Check if a value is an error constructor.
*/
export default function isErrorConstructor(value: unknown): value is ErrorConstructor;
declare const isErrorConstructor: {
/**
Check if a value is an error constructor.
@example
```
import isErrorConstructor = require('is-error-constructor');
isErrorConstructor(Error);
//=> true
isErrorConstructor(RangeError);
//=> true
function FakeError() {}
isErrorConstructor(FakeError);
//=> false
class UnicornError extends Error {}
isErrorConstructor(UnicornError);
//=> true
```
*/
(value: unknown): value is ErrorConstructor;

// TODO: Remove this for the next major release, refactor the whole definition to:
// declare function isErrorConstructor(value: unknown): value is ErrorConstructor;
// export = isErrorConstructor;
default: typeof isErrorConstructor;
};

export = isErrorConstructor;
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ const isErrorConstructor = constructor =>
constructor === Error || constructor.prototype instanceof Error;

module.exports = isErrorConstructor;
// TODO: Remove this for the next major release
module.exports.default = isErrorConstructor;
4 changes: 2 additions & 2 deletions index.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {expectType} from 'tsd-check';
import isErrorConstructor from '.';
import {expectType} from 'tsd';
import isErrorConstructor = require('.');

const foo = 'foo';

Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"node": ">=8"
},
"scripts": {
"test": "xo && ava && tsd-check"
"test": "xo && ava && tsd"
},
"files": [
"index.js",
Expand All @@ -29,8 +29,8 @@
"instanceof"
],
"devDependencies": {
"ava": "^1.3.1",
"tsd-check": "^0.3.0",
"ava": "^1.4.1",
"tsd": "^0.7.2",
"xo": "^0.24.0"
}
}

0 comments on commit 4019dd8

Please sign in to comment.