Skip to content

Commit

Permalink
Refactor TypeScript definition to CommonJS compatible export (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
BendingBender authored and sindresorhus committed Apr 2, 2019
1 parent c7ad279 commit 15e5d94
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 10 deletions.
19 changes: 14 additions & 5 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
/**
Make unhandled promise rejections fail hard right away instead of the default [silent fail](https://gist.github.com/benjamingr/0237932cee84712951a2).
declare const hardRejection: {
/**
Make unhandled promise rejections fail hard right away instead of the default [silent fail](https://gist.github.com/benjamingr/0237932cee84712951a2).
@param log - Custom logging function to print the rejected promise. Receives the error stack. Default: `console.error`.
*/
export default function hardRejection(log?: (stack?: string) => void): void;
@param log - Custom logging function to print the rejected promise. Receives the error stack. Default: `console.error`.
*/
(log?: (stack?: string) => void): void;

// TODO: Remove this for the next major release, refactor the whole definition to:
// declare function hardRejection(log?: (stack?: string) => void): void;
// export = hardRejection;
default: typeof hardRejection;
};

export = hardRejection;
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ const hardRejection = (log = console.error) => {
};

module.exports = hardRejection;
// TODO: Remove this for the next major release
module.exports.default = hardRejection;
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 hardRejection from '.';
import {expectType} from 'tsd';
import hardRejection = require('.');
import './register';

expectType<void>(hardRejection());
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": ">=6"
},
"scripts": {
"test": "xo && ava && tsd-check"
"test": "xo && ava && tsd"
},
"files": [
"index.js",
Expand All @@ -39,9 +39,9 @@
"immediately"
],
"devDependencies": {
"ava": "^1.3.1",
"ava": "^1.4.1",
"execa": "^1.0.0",
"tsd-check": "^0.5.0",
"tsd": "^0.7.1",
"xo": "^0.24.0"
}
}

0 comments on commit 15e5d94

Please sign in to comment.