fix(01-review): IN-02 migrate Logger and ContentLogger to unknown[] args
This commit is contained in:
@@ -1,4 +1,11 @@
|
||||
// Логгер для Service Worker
|
||||
// IN-02 fix: migrated from `...args: any[]` to `...args: unknown[]` so
|
||||
// the type signature matches OffscreenLogger and aligns with strict-
|
||||
// mode hygiene. console.log accepts unknown[] natively (its variadic
|
||||
// signature is `(...data: any[]) => void`, so passing unknown values
|
||||
// works fine — the underlying console.* coerces with String() / object
|
||||
// inspection). Call sites at content/popup/background passed already-
|
||||
// typed values, so no widening was required.
|
||||
export class Logger {
|
||||
private context: string;
|
||||
|
||||
@@ -6,25 +13,25 @@ export class Logger {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
private logWithLevel(level: 'log' | 'warn' | 'error', ...args: any[]) {
|
||||
private logWithLevel(level: 'log' | 'warn' | 'error', ...args: unknown[]) {
|
||||
const timestamp = new Date().toISOString();
|
||||
console[level](`[SW:${this.context}] ${timestamp}`, ...args);
|
||||
}
|
||||
|
||||
log(...args: any[]) {
|
||||
log(...args: unknown[]) {
|
||||
this.logWithLevel('log', ...args);
|
||||
}
|
||||
|
||||
warn(...args: any[]) {
|
||||
warn(...args: unknown[]) {
|
||||
this.logWithLevel('warn', ...args);
|
||||
}
|
||||
|
||||
error(...args: any[]) {
|
||||
error(...args: unknown[]) {
|
||||
this.logWithLevel('error', ...args);
|
||||
}
|
||||
}
|
||||
|
||||
// Логгер для Content Script
|
||||
// Логгер для Content Script (IN-02 fix: see Logger above)
|
||||
export class ContentLogger {
|
||||
private context: string;
|
||||
|
||||
@@ -32,27 +39,27 @@ export class ContentLogger {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
private logWithLevel(level: 'log' | 'warn' | 'error', ...args: any[]) {
|
||||
private logWithLevel(level: 'log' | 'warn' | 'error', ...args: unknown[]) {
|
||||
const timestamp = new Date().toISOString();
|
||||
console[level](`[CS:${this.context}] ${timestamp}`, ...args);
|
||||
}
|
||||
|
||||
log(...args: any[]) {
|
||||
log(...args: unknown[]) {
|
||||
this.logWithLevel('log', ...args);
|
||||
}
|
||||
|
||||
warn(...args: any[]) {
|
||||
warn(...args: unknown[]) {
|
||||
this.logWithLevel('warn', ...args);
|
||||
}
|
||||
|
||||
error(...args: any[]) {
|
||||
error(...args: unknown[]) {
|
||||
this.logWithLevel('error', ...args);
|
||||
}
|
||||
}
|
||||
|
||||
// Логгер для Offscreen Document
|
||||
// Note: uses `...args: unknown[]` (strict-mode hygiene) vs Logger / ContentLogger
|
||||
// which retain the legacy `...args: any[]` — see plan 01-03 style_divergence_note.
|
||||
// All three loggers now share the same `...args: unknown[]` signature
|
||||
// (IN-02 fix retired the style divergence noted in plan 01-03).
|
||||
export class OffscreenLogger {
|
||||
private context: string;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user