[log-process-errors] Add type definitions for 'log-process-errors' (#35464)

* Add base type definitions for log-process-errors.

* Correct return type of LogProcessErrors function.

* Add log-process-errors tests.

* Add tsconfig and tslint for log-process-errors.

* Correct import path for log-process-errors-tests.ts.

* Define minimal compatible TypeScript version for log-process-errors

* Correct placement of log-process-errors type definitions.

* Make options in LogProcessErrors function optional

* Define `testing` and `colors` properties of LogProcessErrorsOptions as optional.

* Use camelCase for logProcessErrors function to be more inline with log-process-errors' documentation.

* Correct log-process-errors exports.

* Remove redundant exports from logProcessErrors namespace.
This commit is contained in:
Jørgen Vatle
2019-05-15 16:16:17 -07:00
committed by Nathan Shively-Sanders
parent 7dda14dff5
commit 695b694eb9
4 changed files with 118 additions and 0 deletions
+68
View File
@@ -0,0 +1,68 @@
// Type definitions for log-process-errors 4.1
// Project: https://git.io/fhSGY
// Definitions by: Jørgen Vatle <https://github.com/JorgenVatle>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.1
declare namespace logProcessErrors {
/**
* Log level
*/
type LogLevel = 'debug' | 'info' | 'warn' | 'error' | 'silent' | 'default';
/**
* Exception type.
*/
type ExceptionType = 'uncaughtException' | 'unhandledRejection' | 'rejectionHandled' | 'multipleResolves' | 'warning';
/**
* log-process-errors constructor options.
*/
interface Options {
/**
* Override logger
*
* @link https://github.com/ehmicky/log-process-errors/blob/master/docs/API.md#log
*/
log?(error: Error, level: LogLevel): Promise<void> | void;
/**
* Which log level to use for different exceptions.
*
* https://github.com/ehmicky/log-process-errors/blob/master/docs/API.md#log
*/
level?: Partial<Record<ExceptionType, LogLevel>> & {
default?(error: Error): 'silent' | 'default';
};
/**
* Which process should trigger `process.exit(1)`
*
* @link https://github.com/ehmicky/log-process-errors/blob/master/docs/API.md#exiton
*/
exitOn?: ExceptionType[];
/**
* When running tests, makes them fail if there are any process errors.
*
* @link https://github.com/ehmicky/log-process-errors/blob/master/docs/API.md#testing
*/
testing?: 'ava' | 'mocha' | 'jasmine' | 'tape' | 'node-tap';
/**
* Whether or not to colorize messages.
*
* @link https://github.com/ehmicky/log-process-errors/blob/master/docs/API.md#colors
*/
colors?: boolean;
}
}
/**
* Log Process Errors
*
* @link https://github.com/ehmicky/log-process-errors/blob/master/docs/API.md#logprocesserrorsoptions
*/
declare function logProcessErrors(options?: logProcessErrors.Options): () => void;
export = logProcessErrors;
@@ -0,0 +1,24 @@
import * as LogProcessErrors from 'log-process-errors';
/**
* Initialize log-process-errors with example options.
*/
const reset = LogProcessErrors({
log(error, level) {
const someErr: Error = error;
const someLogLevel: LogProcessErrors.LogLevel = level;
},
level: { multipleResolves: 'debug' },
exitOn: ['uncaughtException', 'unhandledRejection'],
testing: 'ava',
colors: false,
});
/**
* Restore default Node.js error handling functionality.
*/
reset();
+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",
"log-process-errors-tests.ts"
]
}
+3
View File
@@ -0,0 +1,3 @@
{
"extends": "dtslint/dt.json"
}