Update typings

This commit is contained in:
Erik 2023-12-04 15:15:03 +02:00
parent 22f5549bc7
commit 3e55182657
4 changed files with 9 additions and 6 deletions

View File

@ -9,16 +9,17 @@ type TransportOptions = {
} & WriteOptions } & WriteOptions
const validKeys = [ 'labels' ]; const validKeys = [ 'labels' ];
const isTransportOpts = (obj: object): obj is TransportOptions => const isTransportOpts = (obj: unknown): obj is TransportOptions =>
{ {
if (!obj || typeof obj !== 'object')
return false;
const isWriteOption = isWriteOptions(obj); const isWriteOption = isWriteOptions(obj);
const keys = Object.keys(obj); const keys = Object.keys(obj);
return isWriteOption || keys.some(key => validKeys.includes(key)); return isWriteOption || keys.some(key => validKeys.includes(key));
}; };
class LoggerClient implements Logger class LoggerClient implements Logger
{ {
static MaxChars = 0; static MaxChars = 0;
[key: string]: LogFunction | unknown; [key: string]: LogFunction | unknown;

View File

@ -208,7 +208,7 @@ class MasterLogger implements Logger
}); });
} }
write (type = 'info', ...args: [...entries: Loggable[], options: WriteOptions]) write (type = 'info', ...args: [...entries: Loggable[], options: WriteOptions | Loggable])
{ {
const last = args[args.length - 1]; const last = args[args.length - 1];
let { subheader = '', shard, broadcast = false, labels = [] }: WriteOptions = {}; let { subheader = '', shard, broadcast = false, labels = [] }: WriteOptions = {};

View File

@ -10,8 +10,10 @@ export const makePlainError = (err: Error) =>
}; };
const validKeys = [ 'subheader', 'shard', 'broadcast', 'labels' ]; const validKeys = [ 'subheader', 'shard', 'broadcast', 'labels' ];
export const isWriteOptions = (obj: object, extended = false): obj is WriteOptions => export const isWriteOptions = (obj: unknown, extended = false): obj is WriteOptions =>
{ {
if (!obj || typeof obj !== 'object')
return false;
const keys = Object.keys(obj); const keys = Object.keys(obj);
// Check for invalid keys, in some cases an arbitrary object might share keys // Check for invalid keys, in some cases an arbitrary object might share keys
// while still allowing for an option to be extended // while still allowing for an option to be extended

View File

@ -23,6 +23,6 @@ type IPCMessage = {
type LogFunction = (str: string, opts?: WriteOptions) => void type LogFunction = (str: string, opts?: WriteOptions) => void
type Loggable = string | number | object | Error type Loggable = string | number | object | Error | unknown
export { WriteOptions, Shard, IPCMessage, LogFunction, Loggable }; export { WriteOptions, Shard, IPCMessage, LogFunction, Loggable };