Skip to content

Commit

Permalink
Work around api-extractor import bug
Browse files Browse the repository at this point in the history
The import expression for the ETW trace types breaks API extractor; it
outputs a named import for a non-existent name in the module rather than
emitting a default import. For now, redeclare the type locally and then
use a conditional type to verify that what we have is compatible with
the upstream type when type checking locally.
  • Loading branch information
jakebailey committed Sep 16, 2022
1 parent a64011e commit c7ebf14
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion src/compiler/perfLogger.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,38 @@
import { noop } from "./_namespaces/ts";

type PerfLogger = typeof import("@microsoft/typescript-etw");
/** @internal */
interface PerfLogger {
logEvent(msg: string): void;
logErrEvent(msg: string): void;
logPerfEvent(msg: string): void;
logInfoEvent(msg: string): void;
logStartCommand(command: string, msg: string): void;
logStopCommand(command: string, msg: string): void;
logStartUpdateProgram(msg: string): void;
logStopUpdateProgram(msg: string): void;
logStartUpdateGraph(): void;
logStopUpdateGraph(): void;
logStartResolveModule(name: string): void;
logStopResolveModule(success: string): void;
logStartParseSourceFile(filename: string): void;
logStopParseSourceFile(): void;
logStartReadFile(filename: string): void;
logStopReadFile(): void;
logStartBindFile(filename: string): void;
logStopBindFile(): void;
logStartScheduledOperation(operationId: string): void;
logStopScheduledOperation(): void;
}

type ImportedPerfLogger = typeof import("@microsoft/typescript-etw");

// Assert that our PerfLogger type is compatible with the library.
// TODO(jakebailey): remove this workaround for an api-extractor bug.
const _perfLoggerCorrectType: PerfLogger extends ImportedPerfLogger ? true : false = true;

// eslint-disable-next-line @typescript-eslint/no-unused-expressions
_perfLoggerCorrectType;

const nullLogger: PerfLogger = {
logEvent: noop,
logErrEvent: noop,
Expand Down

0 comments on commit c7ebf14

Please sign in to comment.