Add type declarations for [bristol] logger (#38042)

* [bristol] Added types for bristol logger

* [bristol] made recommended changes for most common use cases
This commit is contained in:
Elliott Campbell 2019-09-09 12:46:25 -05:00 committed by Andrew Casey
parent 3edb6857d0
commit a1b4916891
4 changed files with 77 additions and 0 deletions

View File

@ -0,0 +1,17 @@
import bristol = require('bristol');
bristol.addTarget('console');
bristol.info('Things be working.', {});
bristol.addTarget('console').withFormatter('human');
bristol.debug('Hello, world', { code: 404 });
const uhoh = {
code: 500,
error: {
message: 'Something broke',
reason: 'idk why though',
},
};
bristol.error('Something went wrong', uhoh);

36
types/bristol/index.d.ts vendored Normal file
View File

@ -0,0 +1,36 @@
// Type definitions for bristol 0.4
// Project: https://github.com/TomFrost/Bristol
// Definitions by: Eric Heikes <https://github.com/eheikes>
// Elliott Campbell <https://github.com/ElliottCampbellJHA>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// Caveat: Currently, .d.ts files are unable to handle this package fully
// as it requires both class and namespace be exported.
interface LogError {
message?: string;
reason?: any;
stack?: any;
}
interface LogData {
code?: number;
id?: string;
path?: string;
error?: LogError;
data?: any;
}
declare class Bristol {
addTarget(target: any, opts?: any): any;
withFormatter(formatter: string): any;
withLowestSeverity(severity: string): any;
info(message: string, data: LogData): any;
warn(message: string, data: LogData): any;
error(message: string, data: LogData): any;
debug(message: string, data: LogData): any;
}
declare const bristol: Bristol;
export = bristol;

View File

@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"bristol-tests.ts"
]
}

View File

@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }