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,8 +9,10 @@ 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));
@ -18,7 +20,6 @@ const isTransportOpts = (obj: object): obj is TransportOptions =>
class LoggerClient implements Logger
{
static MaxChars = 0;
[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];
let { subheader = '', shard, broadcast = false, labels = [] }: WriteOptions = {};

View File

@ -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

View File

@ -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 };