implemented types for death v1.1.0 (#36029)

This commit is contained in:
Cameron Knight
2019-06-07 18:38:35 -07:00
committed by Andrew Casey
parent bfb6b8fb61
commit d311e1d311
4 changed files with 108 additions and 0 deletions
+18
View File
@@ -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"
) => {}
);
+66
View File
@@ -0,0 +1,66 @@
// Type definitions for death 1.1
// Project: https://github.com/jprichardson/node-death
// Definitions by: Cameron Knight <https://github.com/ckknight>
// 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;
+23
View File
@@ -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"
]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }