From 3e5518265762dde52290086453bd67e729d512c5 Mon Sep 17 00:00:00 2001 From: "Navy.gif" Date: Mon, 4 Dec 2023 15:15:03 +0200 Subject: [PATCH] Update typings --- src/LoggerClient.ts | 7 ++++--- src/MasterLogger.ts | 2 +- src/Shared.ts | 4 +++- src/Types.ts | 2 +- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/LoggerClient.ts b/src/LoggerClient.ts index 5529757..8f98566 100644 --- a/src/LoggerClient.ts +++ b/src/LoggerClient.ts @@ -9,16 +9,17 @@ type TransportOptions = { } & WriteOptions 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 keys = Object.keys(obj); return isWriteOption || keys.some(key => validKeys.includes(key)); }; -class LoggerClient implements Logger +class LoggerClient implements Logger { - static MaxChars = 0; [key: string]: LogFunction | unknown; diff --git a/src/MasterLogger.ts b/src/MasterLogger.ts index a160e02..f544c39 100644 --- a/src/MasterLogger.ts +++ b/src/MasterLogger.ts @@ -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]; let { subheader = '', shard, broadcast = false, labels = [] }: WriteOptions = {}; diff --git a/src/Shared.ts b/src/Shared.ts index 97ce379..44731cc 100644 --- a/src/Shared.ts +++ b/src/Shared.ts @@ -10,8 +10,10 @@ export const makePlainError = (err: Error) => }; 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); // Check for invalid keys, in some cases an arbitrary object might share keys // while still allowing for an option to be extended diff --git a/src/Types.ts b/src/Types.ts index 186ea60..df1ded6 100644 --- a/src/Types.ts +++ b/src/Types.ts @@ -23,6 +23,6 @@ type IPCMessage = { 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 }; \ No newline at end of file