From 4019dd8aadd034656985342c1952f0fca18da71a Mon Sep 17 00:00:00 2001 From: Dimitri Benin Date: Fri, 5 Apr 2019 06:13:35 +0000 Subject: [PATCH] Refactor TypeScript definition to CommonJS compatible export (#3) --- index.d.ts | 36 ++++++++++++++++++++++++++++++++---- index.js | 1 + index.test-d.ts | 4 ++-- package.json | 6 +++--- 4 files changed, 38 insertions(+), 9 deletions(-) diff --git a/index.d.ts b/index.d.ts index 72553dd..c5b37ae 100644 --- a/index.d.ts +++ b/index.d.ts @@ -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; diff --git a/index.js b/index.js index b277bab..51ce6a9 100644 --- a/index.js +++ b/index.js @@ -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; diff --git a/index.test-d.ts b/index.test-d.ts index 4176067..4c1afef 100644 --- a/index.test-d.ts +++ b/index.test-d.ts @@ -1,5 +1,5 @@ -import {expectType} from 'tsd-check'; -import isErrorConstructor from '.'; +import {expectType} from 'tsd'; +import isErrorConstructor = require('.'); const foo = 'foo'; diff --git a/package.json b/package.json index f5f7616..952c917 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "node": ">=8" }, "scripts": { - "test": "xo && ava && tsd-check" + "test": "xo && ava && tsd" }, "files": [ "index.js", @@ -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" } }