From 85e19f52bce7e8b00f707cce603046fb80f6acea Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Tue, 13 Sep 2022 09:51:00 -0700 Subject: [PATCH] Work around api-extractor import bug 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. --- src/compiler/perfLogger.ts | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/src/compiler/perfLogger.ts b/src/compiler/perfLogger.ts index 34a59208d68f0..a05874a303d08 100644 --- a/src/compiler/perfLogger.ts +++ b/src/compiler/perfLogger.ts @@ -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,