Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature(types): add type definitions #51

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
declare namespace signalExit {
export interface SignalExitOptions {
/**
* Run this handler after any other signal or exit handlers.
* This causes `process.emit` to be monkeypatched.
*
* Default: `false`
*/
alwaysLast?: boolean;
}

/**
* Removes the corresponding listener.
*/
export type RemoveListener = () => void;

/**
* The exit listener is passed two arguments.
*
* It is guaranteed that exactly one of them is `null` and the other not.
*
* - `code`: Exit code of the process. Present for example when Node exits
* normally (end of program) or after `process.exit(code)`.
* - `signal`: Signal causing the process to exit. Present for example
* when using `process.kill(process.pid, signal)`.
*/
export type SignalExitListener = (code: number | null, signal: NodeJS.Signals | null) => any;

export interface SignalExit {
/**
* Adds a listener fired when the current process exits, no matter how.
*
* Note that the function *only* fires for signals if the signal would
* cause the proces to exit. That is, there are no other listeners, and
* it is a fatal signal.
*
* @param listener See [[SignalExitListener]].
* @param options See [[SignalExitOptions]].
* @return Function to remove the listener.
*/
(listener: SignalExitListener, options?: Readonly<SignalExitOptions>): RemoveListener;

/**
* Returns the platform-dependent list of exit signals.
*/
signals(): NodeJS.Signals[];
}
}

declare const signalExit: signalExit.SignalExit;

export = signalExit;
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "3.0.2",
"description": "when you want to fire an event no matter how a process exits.",
"main": "index.js",
"types": "index.d.ts",
"scripts": {
"pretest": "standard",
"test": "tap --timeout=240 ./test/*.js --cov",
Expand All @@ -11,6 +12,7 @@
},
"files": [
"index.js",
"index.d.ts",
"signals.js"
],
"repository": {
Expand Down