Skip to content

Commit 80eefd8

Browse files
D34THWINGSPooya Parsa
authored and
Pooya Parsa
committedJul 21, 2019
feat: improve typescript type definitions (#57)
1 parent e11e91b commit 80eefd8

File tree

1 file changed

+73
-36
lines changed

1 file changed

+73
-36
lines changed
 

Diff for: ‎types/consola.d.ts

+73-36
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,92 @@
1-
declare interface ConsolaReporter {
2-
log: (logObj: any, { async, stdout, stderr }: any) => void
1+
export interface ConsolaLogObject {
2+
level?: number,
3+
tag?: string,
4+
type?: string,
5+
message?: string,
6+
additional?: string | string[],
7+
args?: any[],
38
}
49

5-
declare class Consola {
10+
type ConsolaMock = (...args: any) => void
11+
12+
type ConsolaMockFn = (type: string, defaults: ConsolaLogObject) => ConsolaMock
13+
14+
export interface ConsolaReporterArgs {
15+
async: boolean,
16+
stdout: any,
17+
stderr: any,
18+
}
19+
20+
export interface ConsolaReporter {
21+
log: (logObj: ConsolaLogObject, args: ConsolaReporterArgs) => void
22+
}
23+
24+
export interface ConsolaOptions {
25+
reporters?: ConsolaReporter[],
26+
types?: { [type: string]: ConsolaLogObject },
27+
level?: number,
28+
defaults?: ConsolaLogObject,
29+
async?: boolean,
30+
stdout?: any,
31+
stderr?: any,
32+
mockFn?: ConsolaMockFn,
33+
throttle?: number,
34+
}
35+
36+
export declare class Consola {
37+
constructor(options: ConsolaOptions)
38+
639
// Built-in log levels
7-
static fatal(message: any, ...args: any[]): void
8-
static error(message: any, ...args: any[]): void
9-
static warn(message: any, ...args: any[]): void
10-
static log(message: any, ...args: any[]): void
11-
static info(message: any, ...args: any[]): void
12-
static start(message: any, ...args: any[]): void
13-
static success(message: any, ...args: any[]): void
14-
static ready(message: any, ...args: any[]): void
15-
static debug(message: any, ...args: any[]): void
16-
static trace(message: any, ...args: any[]): void
40+
fatal(message: ConsolaLogObject | any, ...args: any[]): void
41+
error(message: ConsolaLogObject | any, ...args: any[]): void
42+
warn(message: ConsolaLogObject | any, ...args: any[]): void
43+
log(message: ConsolaLogObject | any, ...args: any[]): void
44+
info(message: ConsolaLogObject | any, ...args: any[]): void
45+
start(message: ConsolaLogObject | any, ...args: any[]): void
46+
success(message: ConsolaLogObject | any, ...args: any[]): void
47+
ready(message: ConsolaLogObject | any, ...args: any[]): void
48+
debug(message: ConsolaLogObject | any, ...args: any[]): void
49+
trace(message: ConsolaLogObject | any, ...args: any[]): void
1750

1851
// Create
19-
static create(options: any): typeof Consola
20-
static withDefaults(defaults: any): typeof Consola
52+
create(options: ConsolaOptions): Consola
53+
withDefaults(defaults: ConsolaLogObject): Consola
2154

22-
static withTag(tag: string): typeof Consola
23-
static withScope(tag: string): typeof Consola
55+
withTag(tag: string): Consola
56+
withScope(tag: string): Consola
2457

2558
// Reporter
26-
static addReporter(reporter: ConsolaReporter): typeof Consola
27-
static setReporters(reporters: Array<ConsolaReporter>): typeof Consola
59+
addReporter(reporter: ConsolaReporter): Consola
60+
setReporters(reporters: Array<ConsolaReporter>): Consola
2861

29-
static removeReporter(reporter: any): typeof Consola
30-
static remove(reporter: any): typeof Consola
31-
static clear(reporter: any): typeof Consola
62+
removeReporter(reporter: ConsolaReporter): Consola
63+
remove(reporter: ConsolaReporter): Consola
64+
clear(reporter: ConsolaReporter): Consola
3265

3366
// Wrappers
34-
static wrapAll(): void
35-
static restoreAll(): void
36-
static wrapConsole(): void
37-
static restoreConsole(): void
38-
static wrapStd(): void
39-
static restoreStd(): void
67+
wrapAll(): void
68+
restoreAll(): void
69+
wrapConsole(): void
70+
restoreConsole(): void
71+
wrapStd(): void
72+
restoreStd(): void
4073

4174
// Pause/Resume
42-
static pauseLogs(): void
43-
static pause(): void
75+
pauseLogs(): void
76+
pause(): void
4477

45-
static resumeLogs(): void
46-
static resume(): void
78+
resumeLogs(): void
79+
resume(): void
4780

4881
// Mock
49-
static mockTypes(mockFn: any): any
50-
static mock(mockFn: any): any
82+
mockTypes(mockFn: ConsolaMockFn): any
83+
mock(mockFn: ConsolaMockFn): any
5184
}
5285

53-
declare module 'consola' {
54-
export default Consola
86+
export declare class BrowserReporter implements ConsolaReporter {
87+
log: (logObj: ConsolaLogObject, args: ConsolaReporterArgs) => void
5588
}
89+
90+
declare const consolaGlobalInstance: Consola;
91+
92+
export default consolaGlobalInstance

0 commit comments

Comments
 (0)
Please sign in to comment.