[console-log-level] initial types (#27506)

* [console-log-level] initial types

* [squash] address review feedback

* [squash] export more types in namespace
This commit is contained in:
Ali Ijaz Sheikh 2018-07-24 10:19:59 -07:00 committed by Andy
parent 1dc66757c0
commit 045d74baf3
4 changed files with 67 additions and 0 deletions

View File

@ -0,0 +1,20 @@
import consoleLogLevel = require("console-log-level");
const logger1 = consoleLogLevel({
level: "trace",
stderr: undefined,
prefix: () => "SOME PREFIX"
});
const logger2 = consoleLogLevel({
level: "trace",
stderr: true,
prefix: "OTHER PREFIX"
});
logger1.trace("hello %s", "world");
logger2.debug("hello %s", "world");
logger2.info("hello %s", "world");
logger2.warn("hello %s", "world");
logger2.error("hello %s", "world");
logger2.fatal("hello %s", "world");

23
types/console-log-level/index.d.ts vendored Normal file
View File

@ -0,0 +1,23 @@
// Type definitions for console-log-level 1.4
// Project: https://github.com/watson/console-log-level
// Definitions by: Ali Ijaz Sheikh <https://github.com/ofrobots>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.1
type PrefixFunction = (level: string) => string;
declare namespace consoleLogLevel {
type LogLevelNames =
"trace" | "debug" | "info" | "warn" | "error" | "fatal";
type Logger = Record<LogLevelNames, (...args: any[]) => void>;
}
interface Options {
level?: consoleLogLevel.LogLevelNames;
prefix?: string | PrefixFunction;
stderr?: boolean;
}
declare function consoleLogLevel(opts: Options): consoleLogLevel.Logger;
export = consoleLogLevel;

View File

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

View File

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