Skip to content

Commit 8e1d802

Browse files
authored
fix: typings for midway config merge (#111)
* fix: typings for midway config merge * fix: typings for midway config merge
1 parent 85cf2b5 commit 8e1d802

File tree

2 files changed

+39
-3
lines changed

2 files changed

+39
-3
lines changed

index.d.ts

+15-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,21 @@
1-
import { LoggerOptions } from './dist/index';
1+
import { ITransport, LoggerOptions, TransportUnionOptions } from './dist/index';
22

33
export * from './dist/index';
44

5+
type WithoutITransport<T> = {
6+
[P in keyof T]: Exclude<T[P], ITransport>;
7+
};
8+
9+
type NewTransportUnionOptions = WithoutITransport<TransportUnionOptions>;
10+
11+
interface ConfigLoggerOptions extends LoggerOptions {
12+
/**
13+
* Output transport
14+
*/
15+
transports?: NewTransportUnionOptions;
16+
}
17+
518
declare module '@midwayjs/core/dist/interface' {
619
// eslint-disable-next-line @typescript-eslint/no-empty-interface
7-
interface MidwayLoggerOptions extends LoggerOptions {}
20+
interface MidwayLoggerOptions extends ConfigLoggerOptions {}
821
}

src/interface.ts

+24-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,29 @@ export type LoggerInfo = {
2323
originError?: Error;
2424
};
2525

26+
export interface TransportUnionOptions {
27+
/**
28+
* console transport options
29+
*/
30+
console?: ConsoleTransportOptions | ITransport | false;
31+
/**
32+
* file transport options
33+
*/
34+
file?: FileTransportOptions | ITransport | false;
35+
/**
36+
* error transport options
37+
*/
38+
error?: FileTransportOptions | ITransport | false;
39+
/**
40+
* json transport options
41+
*/
42+
json?: FileTransportOptions | ITransport | false;
43+
/**
44+
* custom transport options
45+
*/
46+
[key: string]: Record<string, any> | ITransport | false;
47+
}
48+
2649
export interface LoggerOptions {
2750
/**
2851
* default level for console,file and json logger
@@ -43,7 +66,7 @@ export interface LoggerOptions {
4366
/**
4467
* Output transport
4568
*/
46-
transports?: Record<string, ITransport | Record<string, any> | false>;
69+
transports?: TransportUnionOptions;
4770
}
4871

4972
export interface ContextLoggerOptions {

0 commit comments

Comments
 (0)