From 8cbc81b8bb715f4d3f0bb441998459c5276af6cc Mon Sep 17 00:00:00 2001 From: RMidhunSuresh Date: Tue, 9 Nov 2021 20:57:47 +0530 Subject: [PATCH] Annotate method arguments --- src/logging/BaseLogger.ts | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/logging/BaseLogger.ts b/src/logging/BaseLogger.ts index 311af22d..7117f9d9 100644 --- a/src/logging/BaseLogger.ts +++ b/src/logging/BaseLogger.ts @@ -21,6 +21,10 @@ import {Platform} from "../platform/web/Platform.js"; // todo: move this to LogItem? type LabelOrValues = string | {l: string; [key: string]: unknown}; +type LogCallback = (item: LogItem) => Promise | undefined; +// todo: this should be an enum +type LogLevel = number | null; +type FilterCreator = ((filter: LogFilter, item: LogItem) => LogFilter) | null; export abstract class BaseLogger { protected _openItems: Set = new Set(); @@ -37,7 +41,7 @@ export abstract class BaseLogger { } /** if item is a log item, wrap the callback in a child of it, otherwise start a new root log item. */ - wrapOrRun(item, labelOrValues: LabelOrValues, callback, logLevel = null, filterCreator = null) { + wrapOrRun(item: LogItem, labelOrValues: LabelOrValues, callback: LogCallback, logLevel: LogLevel = null, filterCreator: FilterCreator = null) { if (item) { return item.wrap(labelOrValues, callback, logLevel, filterCreator); } else { @@ -50,27 +54,27 @@ export abstract class BaseLogger { Useful to pair with LogItem.refDetached. @return {LogItem} the log item added, useful to pass to LogItem.refDetached */ - runDetached(labelOrValues: LabelOrValues, callback, logLevel = null, filterCreator = null) { + runDetached(labelOrValues: LabelOrValues, callback: LogCallback, logLevel: LogLevel = null, filterCreator: FilterCreator = null) { if (logLevel === null) { logLevel = LogLevel.Info; } const item = new LogItem(labelOrValues, logLevel, null, this); - this._run(item, callback, logLevel, filterCreator, false /* don't throw, nobody is awaiting */); + this._run(item, callback, logLevel!, filterCreator, false /* don't throw, nobody is awaiting */); return item; } /** run a callback wrapped in a log operation. Errors and duration are transparently logged, also for async operations. Whatever the callback returns is returned here. */ - run(labelOrValues: LabelOrValues, callback, logLevel = null, filterCreator = null) { + run(labelOrValues: LabelOrValues, callback: LogCallback, logLevel: LogLevel = null, filterCreator: FilterCreator = null) { if (logLevel === null) { logLevel = LogLevel.Info; } const item = new LogItem(labelOrValues, logLevel, null, this); - return this._run(item, callback, logLevel, filterCreator, true); + return this._run(item, callback, logLevel!, filterCreator, true); } - _run(item, callback, logLevel, filterCreator, shouldThrow) { + _run(item: LogItem, callback: LogCallback, logLevel: number, filterCreator: FilterCreator, shouldThrow: boolean) { this._openItems.add(item); const finishItem = () => {