Having trouble understanding the tsserver
error in this static method from the Logger
class.
LogLevel
const enum LogLevel {
ERROR = 0,
WARN = 1
}
export default LogLevel;
Logger
static defaultHandler(level: LogLevel, ...message: readonly string[]) {
if (!Logger.isLevelEnabled(level)) return;
let handler: Function;
switch (level) {
case LogLevel.ERROR:
handler = console.error;
break;
case LogLevel.WARN:
handler = console.warn;
break;
}
// [tsserver 2454] Variable 'handler' is used before being assigned
handler(...message);
}
Given that LogLevel
is an Enum, the handler will never be unassigned. However, adding an if
statement results in a complaint from tslint
.
// [tslint 1] expression is always true (strict-type-predicates)
if (handler !== undefined) handler(...message);
The no-let
rule was even removed from tslint
because it does not recognize the assignment within the switch
case and suggests using const handler: Function;
. Can someone shed some light on this issue?