@@ -52,8 +52,14 @@ export class Consola {
52
52
...this . options . defaults ,
53
53
...types [ type as LogType ] ,
54
54
} ;
55
- ( this as any ) [ type ] = this . _wrapLogFn ( defaults ) ;
56
- ( this as any ) [ type ] . raw = this . _wrapLogFn ( defaults , true ) ;
55
+ // @ts -expect-error
56
+ ( this as unknown as ConsolaInstance ) [ type as LogType ] =
57
+ this . _wrapLogFn ( defaults ) ;
58
+ // @ts -expect-error
59
+ ( this as unknown as ConsolaInstance ) [ type ] . raw = this . _wrapLogFn (
60
+ defaults ,
61
+ true
62
+ ) ;
57
63
}
58
64
59
65
// Use _mockFn if is set
@@ -149,7 +155,9 @@ export class Consola {
149
155
( console as any ) [ "__" + type ] = ( console as any ) [ type ] ; // eslint-disable-line no-console
150
156
}
151
157
// Override
152
- ( console as any ) [ type ] = ( this as any ) [ type ] . raw ; // eslint-disable-line no-console
158
+ ( console as any ) [ type ] = ( this as unknown as ConsolaInstance ) [
159
+ type as LogType
160
+ ] . raw ; // eslint-disable-line no-console
153
161
}
154
162
}
155
163
@@ -169,7 +177,7 @@ export class Consola {
169
177
this . _wrapStream ( this . options . stderr , "log" ) ;
170
178
}
171
179
172
- _wrapStream ( stream : NodeJS . WriteStream | undefined , type : string ) {
180
+ _wrapStream ( stream : NodeJS . WriteStream | undefined , type : LogType ) {
173
181
if ( ! stream ) {
174
182
return ;
175
183
}
@@ -181,7 +189,7 @@ export class Consola {
181
189
182
190
// Override
183
191
( stream as any ) . write = ( data : any ) => {
184
- ( this as any ) [ type ] . raw ( String ( data ) . trim ( ) ) ;
192
+ ( this as unknown as ConsolaInstance ) [ type ] . raw ( String ( data ) . trim ( ) ) ;
185
193
} ;
186
194
}
187
195
@@ -223,10 +231,12 @@ export class Consola {
223
231
}
224
232
225
233
for ( const type in this . options . types ) {
226
- ( this as any ) [ type ] =
227
- _mockFn ( type as LogType , ( this as any ) . options . types [ type ] ) ||
228
- ( this as any ) [ type ] ;
229
- ( this as any ) [ type ] . raw = ( this as any ) [ type ] ;
234
+ ( this as unknown as ConsolaInstance ) [ type as LogType ] =
235
+ _mockFn ( type as LogType , this . options . types [ type as LogType ] ) ||
236
+ ( this as unknown as ConsolaInstance ) [ type as LogType ] ;
237
+ ( this as unknown as ConsolaInstance ) [ type as LogType ] . raw = (
238
+ this as unknown as ConsolaInstance
239
+ ) [ type as LogType ] ;
230
240
}
231
241
}
232
242
@@ -365,8 +375,11 @@ function _normalizeLogLevel(
365
375
return defaultLevel ;
366
376
}
367
377
368
- export type ConsolaInstance = Consola &
369
- Record < LogType , ( message : InputLogObject | any , ...args : any [ ] ) => void > ;
378
+ export interface LogFn {
379
+ ( message : InputLogObject | any , ...args : any [ ] ) : void ;
380
+ raw : ( ...args : any [ ] ) => void ;
381
+ }
382
+ export type ConsolaInstance = Consola & Record < LogType , LogFn > ;
370
383
371
384
// Legacy support
372
385
// @ts -expect-error
0 commit comments