diff --git a/types/death/death-tests.ts b/types/death/death-tests.ts new file mode 100644 index 0000000000..4ab4ecb234 --- /dev/null +++ b/types/death/death-tests.ts @@ -0,0 +1,18 @@ +import ON_DEATH = require("death"); + +const unsub: () => void = ON_DEATH( + (value: "SIGINT" | "SIGTERM" | "SIGQUIT") => {} +); + +const otherUnsub: () => void = ON_DEATH({ + debug: true, + uncaughtException: true, + SIGINT: true, + SIGTERM: true, + SIGQUIT: true, + SIGHUP: true +})( + ( + value: "uncaughtException" | "SIGINT" | "SIGTERM" | "SIGQUIT" | "SIGHUP" + ) => {} +); diff --git a/types/death/index.d.ts b/types/death/index.d.ts new file mode 100644 index 0000000000..629d413660 --- /dev/null +++ b/types/death/index.d.ts @@ -0,0 +1,66 @@ +// Type definitions for death 1.1 +// Project: https://github.com/jprichardson/node-death +// Definitions by: Cameron Knight +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.1 + +/** + * Invokes a callback when a SIGINT, SIGTERM, or SIGQUIT is detected + * on the current node process. + * @param callback The callback to invoke + * @returns A function to unsubscribe and prevent the callback from being invoked + * @example + * ON_DEATH((signal) => { + * console.log('Oh no!'); + * }); + * @example + * const OFF_DEATH = ON_DEATH((signal) => { + * console.log('Oh no!'); + * }); + * // later + * OFF_DEATH(); + */ +declare function ON_DEATH( + callback: (signal: "SIGINT" | "SIGTERM" | "SIGQUIT") => void +): () => void; +/** + * Invokes a callback when a SIGINT, SIGTERM, or SIGQUIT is detected + * on the current node process. Configurable by the provided options. + * + * @param options + * @returns A function to subscribe to the configured death detection + * @example + * ON_DEATH({ + * debug: true, + * uncaughtException: true, + * })((signal) => { + * console.log('Oh no!'); + * }); + * @example + * const OFF_DEATH = ON_DEATH({ + * debug: true, + * uncaughtException: true, + * })((signal) => { + * console.log('Oh no!'); + * }); + * // later + * OFF_DEATH(); + */ +declare function ON_DEATH(options: { + debug?: boolean; + SIGINT?: boolean; + SIGTERM?: boolean; + SIGQUIT?: boolean; + SIGHUP?: boolean; + uncaughtException?: boolean; +}): ( + callback: ( + signal: + | "SIGINT" + | "SIGTERM" + | "SIGQUIT" + | "SIGHUP" + | "uncaughtException" + ) => void +) => () => void; +export = ON_DEATH; diff --git a/types/death/tsconfig.json b/types/death/tsconfig.json new file mode 100644 index 0000000000..b27602b14a --- /dev/null +++ b/types/death/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "death-tests.ts" + ] +} \ No newline at end of file diff --git a/types/death/tslint.json b/types/death/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/death/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }