mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 10:56:53 +00:00
🤖 Merge PR #46270 Fix types for npm package death by @pranaygp
* Fix types for npm package `death` when using `uncaughtException: true`, the handler actually receives an `Error` and an `origin` instead of a signal. furhtermore, SIGHUP is not supported: see:f9453b68b8/lib/death.js (L2-L7)f9453b68b8/lib/death.js (L31)https://nodejs.org/api/process.html#process_event_uncaughtexception * add tests * prettier
This commit is contained in:
parent
9fc4c8ebb8
commit
2e748a87c2
@ -1,18 +1,36 @@
|
||||
import ON_DEATH = require("death");
|
||||
import ON_DEATH = require('death');
|
||||
|
||||
const unsub: () => void = ON_DEATH(
|
||||
(value: "SIGINT" | "SIGTERM" | "SIGQUIT") => {}
|
||||
);
|
||||
const unsub1: () => void = ON_DEATH((value: 'SIGINT' | 'SIGTERM' | 'SIGQUIT') => {});
|
||||
|
||||
const otherUnsub: () => void = ON_DEATH({
|
||||
const unsub2: () => void = ON_DEATH({
|
||||
debug: true,
|
||||
SIGINT: true,
|
||||
SIGTERM: true,
|
||||
SIGQUIT: true,
|
||||
})((value: 'SIGINT' | 'SIGTERM' | 'SIGQUIT') => {});
|
||||
|
||||
const unsub3: () => void = ON_DEATH({
|
||||
debug: true,
|
||||
uncaughtException: true,
|
||||
SIGINT: true,
|
||||
SIGTERM: true,
|
||||
SIGQUIT: true,
|
||||
})((value: 'SIGINT' | 'SIGTERM' | 'SIGQUIT' | Error) => {});
|
||||
|
||||
const unsub4: () => void = ON_DEATH({
|
||||
debug: true,
|
||||
SIGINT: true,
|
||||
SIGTERM: true,
|
||||
SIGQUIT: true,
|
||||
})((value: 'SIGINT' | 'SIGTERM' | 'SIGQUIT') => {});
|
||||
|
||||
const unsub5: () => void = ON_DEATH({
|
||||
debug: true,
|
||||
uncaughtException: true,
|
||||
SIGINT: true,
|
||||
SIGTERM: true,
|
||||
SIGQUIT: true,
|
||||
SIGHUP: true
|
||||
})(
|
||||
(
|
||||
value: "uncaughtException" | "SIGINT" | "SIGTERM" | "SIGQUIT" | "SIGHUP"
|
||||
) => {}
|
||||
// $ExpectError
|
||||
(value: 'SIGINT' | 'SIGTERM' | 'SIGQUIT') => {},
|
||||
);
|
||||
|
||||
52
types/death/index.d.ts
vendored
52
types/death/index.d.ts
vendored
@ -1,9 +1,12 @@
|
||||
// Type definitions for death 1.1
|
||||
// Project: https://github.com/jprichardson/node-death
|
||||
// Definitions by: Cameron Knight <https://github.com/ckknight>
|
||||
// Pranay Prakash <https://github.com/pranaygp>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.1
|
||||
|
||||
type Signal = 'SIGINT' | 'SIGTERM' | 'SIGQUIT';
|
||||
|
||||
/**
|
||||
* Invokes a callback when a SIGINT, SIGTERM, or SIGQUIT is detected
|
||||
* on the current node process.
|
||||
@ -20,9 +23,37 @@
|
||||
* // later
|
||||
* OFF_DEATH();
|
||||
*/
|
||||
declare function ON_DEATH(
|
||||
callback: (signal: "SIGINT" | "SIGTERM" | "SIGQUIT") => void
|
||||
): () => void;
|
||||
declare function ON_DEATH(callback: (arg: Signal) => 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,
|
||||
* })((signal) => {
|
||||
* console.log('Oh no!');
|
||||
* });
|
||||
* @example
|
||||
* const OFF_DEATH = ON_DEATH({
|
||||
* debug: true,
|
||||
* })((signal) => {
|
||||
* console.log('Oh no!');
|
||||
* });
|
||||
* // later
|
||||
* OFF_DEATH();
|
||||
*/
|
||||
declare function ON_DEATH(options: {
|
||||
debug?: boolean;
|
||||
SIGINT?: boolean;
|
||||
SIGTERM?: boolean;
|
||||
SIGQUIT?: boolean;
|
||||
uncaughtException?: false;
|
||||
}): (callback: (signal: Signal) => void) => () => void;
|
||||
|
||||
/**
|
||||
* Invokes a callback when a SIGINT, SIGTERM, or SIGQUIT is detected
|
||||
* on the current node process. Configurable by the provided options.
|
||||
@ -51,16 +82,7 @@ declare function ON_DEATH(options: {
|
||||
SIGINT?: boolean;
|
||||
SIGTERM?: boolean;
|
||||
SIGQUIT?: boolean;
|
||||
SIGHUP?: boolean;
|
||||
uncaughtException?: boolean;
|
||||
}): (
|
||||
callback: (
|
||||
signal:
|
||||
| "SIGINT"
|
||||
| "SIGTERM"
|
||||
| "SIGQUIT"
|
||||
| "SIGHUP"
|
||||
| "uncaughtException"
|
||||
) => void
|
||||
) => () => void;
|
||||
uncaughtException: true;
|
||||
}): (callback: (signalOrErr: Signal | Error, origin?: string) => void) => () => void;
|
||||
|
||||
export = ON_DEATH;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user